import java.util.Scanner; /** This class prints the numeric value of a letter gr
ID: 3623587 • Letter: I
Question
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
This is the program I wrote for it:
public class Grade
{
public getNumericGrade()
{
if (input = A+){
grade = 4.0;}
else if (input = A-)
{grade = 3.7;}
else if (input = B+)
{grade = 3.0;}
else if (input = B-)
{grade = 2.7;}
else if (input = C+)
{grade = 2.0;}
else if (input = C-)
{grade = 1.7;}
else if (input = D+)
{grade = 2.0;}
else if (input = D-)
{grade = 0.7;}
else (input = F)
{grade = 0.0;}
return grade;
}
}
Explanation / Answer
I did not compile your program and run it, but it seems like you are missing a constructor in your grade class. In the GradePrinter class, you say: Grade g = new Grade(input); this implies that in your grade class you have a constructor that takes in a single argument of type string (because you declared input as a string). therefore in the grade class, there must be a constructor something like: public Grade(String inputGrade){ this.input = inputGrade; } you should also declare a string variable input in your grade class (otherwise the constructor I made would make no sense. After adding the variable and the constructor, I see no reason the program shouldn't work.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.