here's my code so far(it's been updated):
import java.util.Scanner;
public class gpa {
public static void main(String[] args) {
double gpa=0;
double input = 0;
String grade= "";
int classes =0;
double fail =0;
do
{
System.out.print("Enter Grade (n to quit): ");
Scanner sc = new Scanner(System.in);
grade = sc.nextLine();
grade = grade.toLowerCase();
if (grade.equals("a"))
{
input = 4.0;
}
if (grade.equals("b"))
{
input = 3.0;
}
if (grade.equals("c"))
{
input = 2.0;
}
if (grade.equals("d"))
{
input = 1.0;
}
if (grade.equals("f"))
{
fail = 1;
}
gpa+=input;
classes++;
} while(grade!="n");
System.out.print("GPA: " + gpa + " ");
gpa/=classes;
if (gpa>=2 && classes >=4 && fail !=1)
{
System.out.print("Eligible");
}
else if(classes <4)
{
System.out.print("Ineligible. less than 4 classes");
}
else if (gpa < 2.0)
{
System.out.print("Ineligible. GPA is less than 2.0");
}
else if (gpa >=2.0 && fail == 1)
{
System.out.print("Ineligible. GPA is above 2.0, but has an F");
}
else if (gpa <2.0 && fail ==1)
{
System.out.print("Ineligible. GPA is below 2.0 and has F");
}
}
}
Here's what I need to be able to output:
- 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
It keeps asking for input. How do I stop this? I tried converting grade into a char but that ended horribly for me. I think it might be a compiler error or something. Any help would be appreciated. Though helpful help would keep my blood pressure down.