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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started