/* This application demonstrate various control structures and additional I/O methods */ import java.io.*; public class GradeAverage { 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; // while loop and if tests while (counter <= NUM) { System.out.print("Enter letter grade: " ); // read a byte from standard input and convert to a char lettergrade = (char)System.in.read(); if (lettergrade == 'A') total += 4; else if (lettergrade == 'B') total += 3; else if (lettergrade == 'C') total += 2; else if (lettergrade == 'D') total += 1; // skips one byte (the return) of standard input System.in.skip (1); counter ++; } // cast to get floating point arithmetic average = (double) total/NUM; System.out.println ("Class average is " + average ); } }