6.4 Quiz Instructions

Using your FileLineQuiz.java program as a starting point, add the ability to save the output to a file.

The program functionality will be identical to FileLineQuiz.java with two exceptions:

  1. You will make a program named FileWriteQuiz.java which also saves the output displayed on the console window in a file named <your name>_WeeklyHoursReport.txt.
  2. While you will still round to 2 places, you do not need to print the extra trailing zero... use a round() method and a normal print() or println() in your output method.

HINT:

  1. Write an output method that takes a string parameter and prints it to both the console and to the output file.
  2. Create a PrintStream field (class variable that is declared outside of all methods) and initialize it inside main() ... example: if the class variable is named outputFile, then in main you will have
    outputFile = new PrintStream(new File("<your name>_WeeklyHoursReport.txt"));
  3. Finally replace your System.out.print calls with calls to the new output method. With the possible exception of adding a round method, the rest of your code will stay exactly the same!
  4. What this does is save you the hassle of having to keep passing the PrintStream to a bunch of methods. If you try to open the PrintStream inside your output method, you will be recreating the output file every time you try to write to it, wiping out everything you'd written to it before. :(

The department files are the same as yesterday and are listed below (save all these files in your work folder).

Please note the first file (FileDoesNotExist.txt) does not ... you guessed it ... exist. Your program must deal gracefully with this case, i.e. not die with an unhandled exception. So, to be clear, you will NOT have a file named FileDoesNotExist.txt in your working folder.

Name your class "<your name>_FileWriteQuiz" and submit the source code to me via DropItToMe

The program must produce the exact output found in: (make sure you use the output comparision tool!)

Remember, in addition to displaying the output on the console window, you will also write it to a file named <your name>_WeeklyHoursReport.txt, the content of which will be identical to that displayed on the console. Make sure you also check the file text for exact match to the expected output!

Quiz Grading

The quiz is worth 35 points.

This is pretty simple...you get 100% if your output exactly matches the expected output...and...0% if it has ANY differences.

Make sure you get all the spelling, capitalization, punctuation, spacing, etc. correct! Hint: copy-n-paste is a wonderful thing! :)