/* Create1.java CIS 111 10/31/07 David Klick This program generates a text file with some randomized data that we can use for a control break report. The file is intended for sequential access use. */ public class Create1 extends CIS111App { public static void main(String[] args) { int month, day, year; int days; double sales; SequentialFile fileout; String filename = "sales.txt"; int recs; // clear screen and open output file clearConsole(); fileout = new SequentialFile(filename, FileMode.OUTPUT); // generate a sales record for each day in // months 10 and 11 of the year 2007 recs = 0; year = 2007; for (month=10; month<=11; month++) { // get the number of days in a particular month days = daysInMonth(month, year); for (day=1; day<=days; day++) { // generate a random amount $30,000.00 - $129,999.99 sales = random(3000000, 12999999) / 100.0; fileout.writeln(year, month, day, sales); recs = recs + 1; } } // display something on screen to let user know program worked println("File created (" + recs + " records total)"); // close output file fileout.close(); } private static int daysInMonth(int m, int y) { // given the month and year, return the number // of days for that month int d = 31; if (m==4 || m==6 || m==9 || m==11) d=30; if (m==2) { d = 28; if (y % 4 == 0) d = 29; if (y % 100 == 0) d = 28; if (y % 400 == 0) d = 29; } return d; } }