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