... user types the end-of-file indicator.
Line 25 inputs a grade value from the user. Line 26 adds grade
to total
. Line 27 increments gradeCounter
. These variables are used to compute the average of the grades. Lines 30–47 use a switch
statement to increment the appropriate letter-grade counter based on the numeric grade entered.
Processing the Grades
The switch
statement (lines 30–47) determines which counter to increment. We assume that the user enters a valid grade in the range 0–100. A grade in the range 90–100 represents A, 80–89 represents B, 70–79 represents C, 60–69 represents D and 0–59 represents F. The switch
statement consists of a block that contains a sequence of case
labels and an optional default
case. These are used in this example ...
Get Java How to Program, Early Objects, 11th 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.