import java.util.*; import java.io.*; public class Enhanced_For { public static void main (String [ ] args) { final String PROMPT = "Please enter a GPA; to quit enter "; final String SENTINEL = "***"; final String AVERAGE_MESSAGE = "\n\nThe average GPA is "; LinkedList gpaList = new LinkedList (); BufferedReader reader = new BufferedReader ( new InputStreamReader (System.in)); String line; double sum = 0; try { while (true) { System.out.println (PROMPT + SENTINEL); line = reader.readLine (); if (line.equals (SENTINEL)) break; gpaList.add (new Double (line)); // inserts in gpaList } // while for (Double gpa : gpaList) sum += gpa; System.out.println (AVERAGE_MESSAGE + (sum / gpaList.size ())); } // try catch (IOException e) { System.out.println (e); } // catch } // method main } // class Enhanced_For