![]() |
School of Engineering and
Applied
Science Department of Computer Science CSci 53 -- Introduction to Software Development http://www.seas.gwu.edu/~csci53/fall04 Prof. Michael B. Feldman mfeldman@gwu.edu |
For example, if the user enters a starting date of May 10, 1999 and an ending date of September 15, 2002, the file will contain a line for each day from May 10 through December of 1999, all of 2000, all of 2001, and all dates in 2002 through September 15. Remember, when turning in your results,be sure to include these output files in their complete and unedited form. This may mean that there will be several pages to turn in.
Your dates should be output in the following format:
In this project you are NOT required to validate the dates or to test with invalid ones; you can assume the user will always enter valid data. However, your test plan must include several date ranges that will test whether your program "rolls over" properly from month to month and year to year. In Project 6 we'll combine this project with the Project 4 validation ideas.
1.
//**************************************************************
2. //
TestData.java
Author: Lewis/Loftus
3. //
4. // Demonstrates the use of a character file
output stream.
5.
//*************************************************************
6.
7. import java.util.Random;
8. import java.io.*;
9.
10. public class TestData
11. {
12.
//------------------------------------------------------------
13. // Creates a file of test data
that consists of ten lines each
14. // containing ten integer values
in the range 10 to 99.
15.
//------------------------------------------------------------
16. public static void main (String[]
args) throws IOException
17. {
18. final int MAX =
10;
19.
20. int value;
21. String file =
"test.dat";
22.
23. Random rand = new
Random();
24.
25. FileWriter fw =
new FileWriter (file);
26. BufferedWriter bw
= new BufferedWriter (fw);
27. PrintWriter outFile
= new PrintWriter (bw);
28.
29. for (int line=1;
line <= MAX; line++)
30. {
31.
for (int num=1; num <= MAX; num++)
32.
{
33.
value = rand.nextInt (90) + 10;
34.
outFile.print (value + " ");
35.
}
36.
outFile.println ();
37. }
38.
39. outFile.close();
40. System.out.println
("Output file has been created: " + file);
41. }
42. }
Here are the key things to notice and incorporate in your program:
Your grade will be calculated on a 20-point basis, as follows:
MBF 10/11/04