/* This application demonstrate various control structures and additional I/O methods */ import java.io.*; public class GradeAvStr { public static void main (String args[]) throws IOException { // declaring a constant variable final int NUM = 5; char lettergrade; int total = 0; int counter = 1; double average; // set up input stream BufferedReader in = new BufferedReader ( new InputStreamReader ( System.in )); // while loop and if tests while (counter <= NUM) { System.out.print("Enter letter grade: " ); // read a line from standard input, trim white space, get firstchar lettergrade = (in.readLine().trim()).charAt(0); if (lettergrade == 'A') total += 4; else if (lettergrade == 'B') total += 3; else if (lettergrade == 'C') total += 2; else if (lettergrade == 'D') total += 1; counter ++; } // cast to get floating point arithmetic average = (double) total/NUM; System.out.println ("Class average is " + average ); } }