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);
	}
}

Should I get rid of all the && statements? I made it work withought them, but I dont know if its correct to do it that way.

Your use of && looks OK to me. That isn't the neatest/shortest way to code it, but as far as I can see it should work as you intended, apart from some marginal cases where the ranges don't quite meet up, eg 3.05, which isn't a B+ or a B
Rather than all those else ifs and the afore-mentioned range problem, you could code it like this:

if (grade >= 4.0) return "A+";
if (grade >= 4.85) return "A"; 
etc
commented: That's a very good suggestion. +6

Thank-you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.