Monday, 12 January 2015

// The "Chapter3_Example4" class.  Chapter 3, Example 4.
// (from the Carter book)

// This multi-way IF statement prints a comment that depends on the value
// of the char variable 'grade'.  Try this with 'grade' values A, B, C, D,
// E, F (remember that E is considered invalid).

import java.awt.*;
import hsa.Console;

public class Chapter3_Example4
{
    static Console c;           // The output console

    public static void main (String[] args)
    {
        c = new Console ();

        char grade = 'F';

        if (grade == 'A')
            c.println ("Excellent");
        else if (grade == 'B')
            c.println ("Good");
        else if (grade == 'C')
            c.println ("Average");
        else if (grade == 'D')
            c.println ("Pass - Fair");
        else if (grade == 'F')
            c.println ("Fail - Poor");
        else
            c.println ("Invalid grade - must be A, B, C, D or F only");

    } // main method
} // Chapter3_Example4 class

No comments:

Post a Comment