Hey. I'm new to Java and I'm trying to make a grades program for a class assignment. This is what I have so far.
[CODE=java]import java.util.Scann er;
import static java.lang.Syste m.out;
public class Grades//Creates Class
{
public static void main(String[] args)
{
Scanner myScanner = new Scanner(System. in);
String grade;
double counter1 = 0.0;//Variables
double counter2 = 0.0;
char i;
char F;
out.println("En ter your grade: ");
grade = myScanner.nextL ine();
while(grade != "q"){
out.println("En ter your grade. Enter q to see whether or not you are eligible: ");
grade = myScanner.nextL ine();
if (grade == "A")
{
counter1 += 4.0;
counter2++;
}
else if (grade == "B")
{
counter1 += 3.0;
counter2++;
}
else if (grade == "C")
{
counter1 += 2.0;
counter2++;
}
else if (grade == "D")
{
counter1 += 1.0;
counter2++;
}
else if (grade == "F")
{
i = 'F';
counter1 += 0.0;
counter2++;
}
}
if (grade == "q"){
if (counter2 < 4){
System.out.prin tln("Ineligible , taking less than 4 classes");
}
else if ((counter2 >= 4) && (counter1/counter2 < 2.0)){
System.out.prin tln("Ineligible , gpa below 2.0");
}
else if (i == 'F')
{
if ((counter2 >= 4) && (counter1 / counter2 < 2.0)){
System.out.prin tln("Inelegible , gpa below 2.0 and has F grade");
}
else ((counter2 >= 4) && (counter1 / counter2 >= 2.0)){
System.out.prin tln("Inelegible , gpa above 2.0 but has F grade");
}
}
else{
System.out.prin tln("GPA = " + (counter1/counter2) + " Eligible");
}
}
}
}[/CODE]
It says stuff like 'i' is not initialized. But when I delete that line of code(I need it there though, just testing it), the string input thing won't stop when I enter q.
[CODE=java]import java.util.Scann er;
import static java.lang.Syste m.out;
public class Grades//Creates Class
{
public static void main(String[] args)
{
Scanner myScanner = new Scanner(System. in);
String grade;
double counter1 = 0.0;//Variables
double counter2 = 0.0;
char i;
char F;
out.println("En ter your grade: ");
grade = myScanner.nextL ine();
while(grade != "q"){
out.println("En ter your grade. Enter q to see whether or not you are eligible: ");
grade = myScanner.nextL ine();
if (grade == "A")
{
counter1 += 4.0;
counter2++;
}
else if (grade == "B")
{
counter1 += 3.0;
counter2++;
}
else if (grade == "C")
{
counter1 += 2.0;
counter2++;
}
else if (grade == "D")
{
counter1 += 1.0;
counter2++;
}
else if (grade == "F")
{
i = 'F';
counter1 += 0.0;
counter2++;
}
}
if (grade == "q"){
if (counter2 < 4){
System.out.prin tln("Ineligible , taking less than 4 classes");
}
else if ((counter2 >= 4) && (counter1/counter2 < 2.0)){
System.out.prin tln("Ineligible , gpa below 2.0");
}
else if (i == 'F')
{
if ((counter2 >= 4) && (counter1 / counter2 < 2.0)){
System.out.prin tln("Inelegible , gpa below 2.0 and has F grade");
}
else ((counter2 >= 4) && (counter1 / counter2 >= 2.0)){
System.out.prin tln("Inelegible , gpa above 2.0 but has F grade");
}
}
else{
System.out.prin tln("GPA = " + (counter1/counter2) + " Eligible");
}
}
}
}[/CODE]
It says stuff like 'i' is not initialized. But when I delete that line of code(I need it there though, just testing it), the string input thing won't stop when I enter q.
Comment