Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that translates a letter grade into a number grade. Letter grade

ID: 3624890 • Letter: W

Question

Write a program that translates a letter grade into a number grade. Letter grades are A B C D F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F-. A + increases the numeric value by 0.3, a - decreases it by 0.3. However, an A+ has the value 4.0. All other inputs have value -1.

Enter a letter grade:
B-
Numeric value: 2.7.

Use a class Grade with a method getNumericGrade.

Use the following class as your main class:

import java.util.Scanner;

/**
This class prints the numeric value of a letter grade given by the user.
*/
public class GradePrinter
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a letter grade:");
String input = in.nextLine();
Grade g = new Grade(input);
double grade = g.getNumericGrade();
System.out.println("Numeric value: " + grade);
}
}


You need to supply the following class in your solution:

Grade

Explanation / Answer

public class Grade { String myInput; Grade(String input) { myInput = input; } public double getNumericGrade() { double theGrade = -1; //in case the input is bad -> return -1 boolean AGrade = false; //special case boolean FGrade = false; //special case if(myInput.length() > 0 && myInput.length() < 3) //we just have a letter and possibly a modifier { switch (myInput.charAt(0)) { case 'A': theGrade = 4; AGrade = true; break; case 'B': theGrade = 3; break; case 'C': theGrade = 2; break; case 'D': theGrade = 1; break; case 'F': theGrade = 0; FGrade = true; } } if(myInput.length() == 2) //we have a modifier (+/-) { switch (myInput.charAt(1)) { case '+': if (!AGrade && !FGrade) { theGrade += .3; } break; case '-': if (!FGrade) { theGrade -= .3; } } } return theGrade; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote