/* GOAL: Create two files, odds.txt and evens.txt, with the first one containing the odd numbers from 1 to 1000, and the second one containing the even ones. HINT: Start with the file WriteData.java TASK BREAKDOWN: --------------- PREPARATION * Copy WriteData.java from the ENGR 131 Code Repository * Copy TextFileIO.java to the same directory * Copy WriteData.java to a new program OddsEvens.java STEP 1: * Edit OddsEvens.java to save 1-1000 in the file all.txt * Compile, Run, Debug. Look at output. STEP 2: * Edit OddsEvens.java to save the odds to file odds.txt * Compile, Run, Debug. Look at output. STEP 3: * Edit OddsEvens.java to also save evens to file evens.txt * Compile, Run, Debug. Look at output. We're done! */ // -- M. Branicky, 10/30/06 import java.io.PrintWriter; // needed for output processing using PrintWriter public class OddsEvens // MODIFIED for OddsEvens { public static void main(String args[]) { // Open the file(s) // ORIG: PrintWriter output = TextFileIO.openWrite("out.txt"); // STEP 1: PrintWriter output = TextFileIO.openWrite("all.txt"); PrintWriter output = TextFileIO.openWrite("odds.txt"); // ADDED for STEP 2 PrintWriter output2 = TextFileIO.openWrite("evens.txt"); // ADDED for STEP 3 // Write output to file(s) for (int i=1; i<=1000; i++ ) // ADDED for STEP 1 { // ADDED for STEP 1 if (i%2==1) { // ADDED for STEP 2 output.println(i); // ADDED for STEP 1 } // ADDED for STEP 2 else output2.println(i); // ADDED for STEP 3 } // ADDED for STEP 1 // Close the file(s) output.close(); // ORIG output2.close(); // ADDED for STEP 3 } }