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: 3536894 • Letter: W

Question

Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and 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 %u2013 decreases it by 0.3. However, an A+ has the value of 4.0. All invalid inputs should display the error message %u201CInvalid Grade Entered%u201D in an Dialog Box and return a value of -1.



Sample Tested Output:

4.0 A+ entered

Expected: 4.0

4.0 A entered

Expected: 4.0

3.0 B entered

Expected: 3.0




-1.0 F+ entered

Expected: -1


Explanation / Answer

public class Grade
{
private String grade;
private double gradeNum;
// Constructor
public Grade(String showGrade)
{
  grade = showGrade;
  gradeNum = 0;
}
String letterGrade = grade.substring(0, 1);
// pass 1 to exclude + or -
if (letterGrade.equalsIgnoreCase("A"))
{
  gradeNum = 4.0;
}
else if(letterGrade.equalsIgnoreCase("B"))
{
  gradeNum = 3.0;
}
else if(letterGrade.equalsIgnoreCase("C"))
{
  gradeNum = 2.0;
}
else if(letterGrade.equalsIgnoreCase("D"))
{
  gradeNum = 1.0;
}
else if(letterGrade.equalsIgnoreCase("F"))
{
  gradeNum = 0.0;
  // return from here if you want
  F= F+ return gradeNum;
  // if you want to invalidate F- and F+ look below
}
else
{
  System.out.println("Invalid letter grade");
  return gradeNum;
  // don't forget to RETURN from here
}
suffix = grade.substring(1);
if (suffix.isEmpty())
{
  // return early if there's no suffix
  return gradeNum;
}
else if(gradeNum == 0.0)
{
  // to invalidate F- and F+
  System.out.println("Invalid letter grade");
  return gradeNum;
}
if(suffix.equals("+"))
{
  gradeNum = gradeNum + .3;
}
else if (suffix.equals("-"))
{
  gradeNum = gradeNum - .3;
}
return gradeNum;
}
}

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