Question: Questions: Write a Java enumeration LetterGrade that represents letter grades A through F, including plus and minus grades (eg, AMINUS, BPLUS, - there is no

Questions: Write a Java enumeration LetterGrade that represents letter grades A through F, including plus and minus grades (eg, AMINUS, BPLUS, - there is no APLUS grade). You will use the Suit enumeration found in the Sakai Week 8 Source Code folder as an example.

Define a private instance variable to hold a boolean value that is true only if the grade is passing. Grades A through C are passing, CMINUS through F are failing (not passing, or false). Also, define a constructor that initializes this instance variable, an accessor method called isPassing() that returns its boolean value (true or false), and a method toString() that returns the grade as a String like "A", "A-", "B+", etc. toString() should use if/else-if/else or switch/case statements to produce the required String result based on the current LetterGrade enumeration value; for example, a value of AMINUS should produce the String "A-".

Finally, run the supplied main method in the LetterGrade enumeration to demonstrate / test the enumeration. Enumerations as classes are covered on pages 449 through 451 of the text.

Template is below:

public enum LetterGrade { /* This enumeration of card suits comes from Suit.java - modify it to match the required LetterGrade enumeration */ /* here is where you define the letter grades together with their passing value, a boolean: passing == true, not passing == false */ CLUBS("black"), DIAMONDS("red"), HEARTS("red"), // replace these with grade names A, AMINUS, ... SPADES("black"); // the value in the parentheses will be true or false for passing/not passing private final String color; // replace this with private final boolean passing private Suit(String suitColor) // replace this with a LetterGrade constructor { color = suitColor; // set passing instead (passing is a boolean) } public String getColor() // replace this with public boolean isPassing() { return color; // return passing instead } /* here is where you add the toString method based on the LetterGrade value - use if/else-if/else or switch/case based on the value of to return the proper String; for example if this == AMINUS, return "A-" */ @Override public String toString() { /* write the toString method here */ } public static void main(String[] args) // supplied for testing - don't change this! { LetterGrade myGrade = AMINUS; // in a separate class it would be LetterGrade.AMINUS LetterGrade yourGrade = CPLUS; LetterGrade theirGrade = D; System.out.println("myGrade is expected to be passing"); System.out.println("myGrade is passing: " + myGrade.isPassing()); System.out.println("yourGrade is also expected to be passing"); System.out.println("yourGrade is passing: " + yourGrade.isPassing()); System.out.println("theirGrade is not expected to be passing"); System.out.println("theirGrade is passing: " + theirGrade.isPassing()); System.out.println("myGrade: " + myGrade); System.out.println("yourGrade: " + yourGrade); System.out.println("theirGrade: " + theirGrade); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!