Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 5. Control Statements: Part 2 > switch Multiple-Selection Statement

5.6. switch Multiple-Selection Statement

Chapter 4 discussed the if single-selection statement and the if...else double-selection statement. The switch multiple-selection statement performs different actions based on the possible values of a constant integral expression of type byte, short, int or char.

GradeBook Class with switch Statement to Count A, B, C, D and F Grades

Figure 5.9 enhances class GradeBook from Chapters 34. The new version we now present not only calculates the average of a set of numeric grades entered by the user, but 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 class also displays a summary of the number of students who received each grade. Refer to Fig. 5.10 for sample inputs and outputs of the GradeBookTest application that uses class GradeBook to process a set of grades.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial