4.7 Student Class: Nested if...else Statements

The example of Figs. 4.44.5 demonstrates a nested if...else statement that determines a student’s letter grade based on the student’s average in a course.

 1   // Fig. 4.4: Student.java 2   // Student class that stores a student name and average. 3   public class Student 4   { 5      private String name; 6      private double average; 7  8      // constructor initializes instance variables 9      public Student(String name, double average)10      {11         this.name = name;12 13         // validate that average is > 0.0 and <= 100.0; otherwise,14         // keep instance variable average's default value (0.0)15         if (average > 0.0)                                           ...

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.