import java.io.*; public class Scores3 { public static void main (String [ ] args) { final String IN_FILE_PROMPT = "\nPlease enter the name of the input file: "; final String OUT_FILE_PROMPT = "\nPlease enter the name of the output file: "; final String HEADING = "Here are the test scores:"; final String RESULT = "\n\nThe sum of the scores is "; final String DONE = "\n\nThe execution of this project has ended."; BufferedReader keyboardReader, fileReader; PrintWriter fileWriter = null; try { boolean filesOK = false; while (!filesOK) { try { keyboardReader = new BufferedReader (new InputStreamReader (System.in)); System.out.print (IN_FILE_PROMPT); fileReader = new BufferedReader (new FileReader (keyboardReader.readLine())); System.out.print (OUT_FILE_PROMPT); fileWriter = new PrintWriter (new BufferedWriter (new FileWriter (keyboardReader.readLine()))); String line; int sum = 0; fileWriter.print (HEADING); while (true) { line = fileReader.readLine (); if (line == null) break; fileWriter.print ("\n" + line); try { sum += Integer.parseInt (line); } // try for NumberFormatException catch (NumberFormatException e) { fileWriter.print (" " + e); } // catch NumberFormatException } // while more scores in input file fileWriter.println (RESULT + sum); filesOK = true; System.out.println (DONE); } // try catch (IOException e) { System.out.println (e); } // catch } // while files not OK } // try finally { fileWriter.close(); } // finally } // method main } // class Scores3