Using a switch Statement to Count A, B, C, D and F Grades

Figure 5.9 calculates the class average of a set of numeric grades entered by the user, and uses a switch statement to determine whether each grade is the equivalent of an A, B, C, D or F and to increment the appropriate grade counter. The program also displays a summary of the number of students who received each grade.

 1   // Fig. 5.9: LetterGrades.java 2   // LetterGrades class uses the switch statement to count letter grades. 3   import java.util.Scanner; 4  5   public class LetterGrades 6   { 7      public static void main(String[] args) 8      { 9         int total = 0; // sum of grades                  10         int gradeCounter = 0; // number of ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.