import java.io.*; public class Scores2Revised { public static void main (String [ ] args) { final String SENTINEL = "***"; final String HEADING = "Here are the test scores:"; final String PROMPT = "Please enter a test score, or "+ SENTINEL + " to quit: "; final String RESULT = "\n\nThe sum of the scores is "; final String DONE = "The execution of this project has ended."; PrintWriter fileWriter = null; try { BufferedReader keyboardReader = new BufferedReader (new InputStreamReader(System.in)); fileWriter = new PrintWriter (new BufferedWriter (new FileWriter("scores.out"))); String line; int sum = 0; fileWriter.print(HEADING); while (true) { System.out.print(PROMPT); line = keyboardReader.readLine(); if (line.equals(SENTINEL)) break; fileWriter.print("\n" + line); try { sum += Integer.parseInt(line); } // try for NumberFormatException catch (NumberFormatException e) { fileWriter.print (" " + e); } // catch NumberFormatException } // while fileWriter.println (RESULT + sum); } // try for IOException catch (IOException e) { System.out.println (e); } // catch IOException finally { fileWriter.close(); System.out.println (DONE); } // finally } // method main } // class Scores2Revised