My assignment is:
"Write a program that accepts the letter grades for a student, calculates the student's gpa, and prints it out, along with one of the following five messages:
Eligible
Ineligible, taking less than 4 classes
Ineligible, gpa below 2.0
Ineligible, gpa above 2.0 but has F grade (note: gpa >= 2.0)
Ineligible, gpa below 2.0 and has F grade"

To be eligible:
"1. No F's.
2. Minimum 2.0 grade point average (gpa) Note: A = 4.0, B = 3.0, C = 2.0, D = 1.0, F = 0
3. Enrollment in a minimum of four academic classes"

I'm just starting with JAVA and I can't get this to work. As of right now I have given up trying to figure out the eligibility parts and am focusing on just the gpa. Every time I run this program I get the answer 0.0 for the gpa. What in the world am I doing wrong. Remember me = noob. If anyone can help me in the right direction, I'd be very greatful. Also, I can't figure out how to get it to stop the loop when you enter Q or q. And how do you store multiple user input values and use them later. Here is one of my 200000 attempts at this.

import javax.swing.JOptionPane;

public class GPA {

	private double gpa = 0.0;
	private int classNum;
	private String gradeInput;
	
	public GPA() {
	}	
	
	public String UserInput(){
		gradeInput = JOptionPane.showInputDialog("Enter Grade:");
		return gradeInput;
	}
	
	public double inputGrade()
	{
	    for(classNum = 1; classNum <= 7; classNum++)
	    {
	    	UserInput();
	    	if((gradeInput == "Q") || (gradeInput == "q"))
	    		gpa = gpa;//its stupposed to stop the loop when you type Q/q
                 //not sure how to make it stop the loop yet
		else if((gradeInput == "A") || (gradeInput == "a"))
			gpa = (gpa + 4.0) / 2;	
		else if((gradeInput == "B") || (gradeInput == "b"))
			gpa = (gpa + 3.0) / 2;	
		else if((gradeInput == "C") || (gradeInput == "c"))
			gpa = (gpa + 2.0) / 2;
		else if((gradeInput == "D") || (gradeInput == "d"))
			gpa = (gpa + 1.0) / 2;
		else if((gradeInput == "F") || (gradeInput == "f"))
			gpa = (gpa + 0.0) / 2;
	    }
	    return gpa;
	}
	
	public static void main(String [] args)
	{
		GPA runProgram = new GPA();
		System.out.print(runProgram.inputGrade());
	}
}
import javax.swing.JOptionPane;

public class GPA {

    private double gpa = 0.0;
    
    public GPA() {
    }    
    
    public String UserInput(){
        gradeInput = JOptionPane.showInputDialog("Enter Grade:");
        return gradeInput;
    }
    
    public void inputGrade()
    {
        for(int classNum = 1; classNum <= 7; classNum++)
        {
           String gradeInput= UserInput(); //dont need to use private variable when passing variables
            if((gradeInput == "Q") || (gradeInput == "q"))
               classNum=8;//makes classNum<=7 false
        else if((gradeInput == "A") || (gradeInput == "a"))
            gpa = (gpa + 4.0) / 2;    
        else if((gradeInput == "B") || (gradeInput == "b"))
            gpa = (gpa + 3.0) / 2;    
        else if((gradeInput == "C") || (gradeInput == "c"))
            gpa = (gpa + 2.0) / 2;
        else if((gradeInput == "D") || (gradeInput == "d"))
            gpa = (gpa + 1.0) / 2;
        else if((gradeInput == "F") || (gradeInput == "f"))
            gpa = (gpa + 0.0) / 2;
        }
  
    }
    
    public static void main(String [] args)
    {
        GPA runProgram = new GPA();
        System.out.print(inputGrade());//dont need to say run program
    }
}

didnt test it but try that

@nschessnerd , you better test it before you submiting something or you may be providing wrong solution an waisting your and poster time...

import javax.swing.JOptionPane;

public class GPA {

	private double gpa = 0.0;
	private int classNum;
	private String gradeInput;
	
	public GPA() {
	}	
	
	public String UserInput(){
		gradeInput = JOptionPane.showInputDialog("Enter Grade:");
		return gradeInput;
	}
	
	public double inputGrade()
	{
		int end = 0;
	    for(classNum = 1; classNum <= 7; classNum++)
	    {
	    	gradeInput = UserInput();
	    	
	    	switch(Character.toLowerCase(gradeInput.charAt(0) ))
	    	{
	    		case 'q' :
	    			classNum = 8;	    			
	    			break;
	    		case 'a':
	    			gpa += 4.0;
	    			end = classNum;
	    			break;
	    		case 'b':
	    			gpa += 3.0;
	    			end = classNum;
	    			break;
	    		case 'c':
	    			gpa += 2.0;
	    			end = classNum;
	    			break;
	    		case 'd':
	    			gpa += 1.0;
	    			end = classNum;
	    			break;
	    		case 'f':
	    			gpa += 0.0;
	    			end = classNum;
	    			break;
	    		default:
	    			break;
	    	} // close switch	    	
	    	
	    }
	    return gpa/end;
	}
	
	public static void main(String [] args)
	{
		GPA runProgram = new GPA();
		System.out.print(runProgram.inputGrade());
	}
}

I understand that gpa should return everage mark so I ajusted calculation. If I'm wrong please corect it as necessary. The code bellow return gpa, so now you have to think how do you gone find if person had any "F" in the results

I tried a switch, but I get getting unexpected type error so gave up with that. Thanks so much, and yes now hmmmm how do you do that 'F' thing, but I think I know a way and if I don't I gotta give it a few trys before I ask for help.

I got it all to work...Thanks for the help Peter_budo.

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.