Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

What is the basic process for finding the bid price?

Answered: 1 week ago

Question

1. The evaluation results can be used to change the program.

Answered: 1 week ago

Question

5. To determine the financial benefits and costs of the program.

Answered: 1 week ago