Grade2 Class....
public class Grade2 {
public Grade2(double input) {
Grade = input;
}
public String getLetterGrade()
{
if(Grade==(4.0))
message="A+";
else if(Grade>=(3.85)&&Grade<=(3.99))
message="A";
else if(Grade>=(3.7)&&Grade<=(3.8499999))
message="A-";
else if(Grade>=(3.01)&&Grade<=(3.3))
message="B+";
else if(Grade>=(2.85)&&Grade<=(3.00))
message="B";
else if(Grade>=(2.7)&&Grade<=(2.8499))
message="B-";
else if(Grade>=(2.01)&&Grade<=(2.3))
message="C+";
else if(Grade>=(1.85)&&Grade<=(2.00))
message="C";
else if(Grade>=(1.7)&&Grade<=(1.849999))
message="C-";
else if(Grade>=(1.01)&&Grade<=(1.3))
message="D+";
else if(Grade>=(0.85)&&Grade<=(1.00))
message="D";
else if(Grade>=(0.7)&&Grade<=(.8499999))
message="D-";
else if(Grade<=(0.699))
message="F";
return message;
}
private double Grade;
private String message;
private String input;
}
Tester Class...
import javax.swing.JOptionPane;
public class Grade2Tester
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("What is your numeric grade");
if (input == null)
System.out.println("Why did you Cancel?");
else
{
Grade2 g = new Grade2(Double.parseDouble(input));
System.out.println("Your letter grade is: " + g.getLetterGrade());
}
System.exit(0);
}
}