// ************************************************************************** // GradesCalculator finds the highest grade and calculates the average grade // based on user input. // // Kelli Wiseth // 29-June-2004 // Platform: Wintel [Windows 2000] // JDK version: JDK 1.4.1 // //****************************************************************************** import java.io.*; class GradesCalculator { public static void main (String args[]) throws IOException { int grade; int count=0; int average; int max; int total=0; //get the first grade, set max to the first grade before entering the loop System.out.print("Please enter the first grade [enter -1 to quit the program]: "); System.out.flush(); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); grade = Integer.parseInt(stdin.readLine()); total = grade; max = grade; while (grade >= 0) { count++; total = total+grade; System.out.print("Enter the next grade [enter -1 when finished]: "); System.out.flush(); grade = Integer.parseInt(stdin.readLine()); if (grade > max) max=grade; } if (count==0) System.out.println("No valid grades were entered"); else { System.out.println(); System.out.println(); System.out.println("-----------------------------------------------"); System.out.println("Average Grade and Maximum Grade for " + count + " grades entered:"); System.out.println("-----------------------------------------------"); System.out.println(); System.out.println("Total grades: " + count); System.out.println("Average grade: " + total/count); System.out.println("Highest grade: " + max); System.out.println(); System.out.println("------------------------------------------------"); } }//main method }//GradesCalculator class