Difference between revisions of "CISC181 S2015 Lab9"
(Created page with "===Preliminaries=== * Make a new project with ''n'' = 9 (following these instructions) * Name your main class "Lab9" (when cre...") |
(No difference)
|
Latest revision as of 10:11, 18 January 2017
Contents
Preliminaries
- Make a new project with n = 9 (following these instructions)
- Name your main class "Lab9" (when creating a new module in the instructions above, in the Java class name field)
Part 1
This section revisits the WordStats section of Lab 6. You may re-use any code from it that you find useful. You may also use this template for WordStats_Timed.java
Make a public class WordStats_Timed which has a constructor that takes the full path name of ONE file to read (no console interaction). Using the same delimiter as Lab 6, write three methods in WordStats_Timed to determine the alphabetically last word in the file:
- readQuiet(): Keep a "current" last word, and compare each new scanned word to it. Update the last word if the new word is "later". Don't print anything.
- readVerbose(): Same thing but for each word read, print it and the current last word to the console with System.out.println()
- readSort(): Add each scanned word to an initially empty ArrayList of Strings, then call Collections.sort() on it and extract the last word. Do not print anything.
Each read* should save the answer in a field which can be read with the public accessor method String getLastWord(). It should also measure the running time of the function with nanoTime() and set a field which can be read with the public accessor method double getElapsedSeconds().
In your main(), read the file "greatexp.txt" 10 times for each method (this may require calling the WordStats_Timed constructor repeatedly), average together the elapsed time for each, and separately report how long each took in seconds with at least 3 digits of precision.
Part 2
Using the Java Date and/or SimpleDateFormat and/or Calendar classes as necessary (see lecture slides), write a method in your Lab9 class called void printMonthCalendar(String dateString) which does the following:
- Takes input as a date in "month/day/year" format (all numbers). For example, this lab was released on "4/20/2015"
- Prints a text-formatted "calendar" for that month which looks roughly like this:
Ignore the font size, etc. The main thing is this:
- First line: Full month name to left, year to right. They don't have to be perfectly aligned with the table below
- Second line: First letter of day of week
- Rest of lines: Dates in month, in correct locations (i.e., lined up with day of week letter). Do not print a number if it belongs to the previous or next month
Test your function by calling it from main() with at least 3 different dates.
Here are some sample inputs and expected outputs:
printMonthCalendar("7/4/1776");
July 1776 S M T W T F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
printMonthCalendar("12/31/1899");
December 1899 S M T W T F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
printMonthCalendar("4/24/2015");
April 2015 S M T W T F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Submission
Submit your Lab9.java and WordStats_Timed.java.