Code:
java.util.Scanner;
publicclass gpa {
publicstaticvoid 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 =newScanner(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");
}
elseif(classes <4)
{
System.out.print("Ineligible. less than 4 classes");
}
elseif(gpa <2.0)
{
System.out.print("Ineligible. GPA is less than 2.0");
}
elseif(gpa >=2.0&& fail ==1)
{
System.out.print("Ineligible. GPA is above 2.0, but has an F");
}
elseif(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.
Source: https://gpahub.net/