letterGrade not print out on my code
import java.util.Scanner;
public class { // BEGIN CLASS
public ()
{
}//END Constructor
public static void main(String[]args)
{//BEGIN main()
Scanner input = new Scanner (System.in);
String letterGrade = "";
String studentName = "";
String bannerID = "";
String course = "";
int grades;
String password = "";
double average = 0.0;
int attempt = 2;
int gradesAttempt;
int counterGradeAttempt = 1;
int gradesTotal = 0;
for (int counter =1; counter <=3; counter += 1)
{
System.out.printf("\nPlease enter the password: ");
password = input.nextLine();
if (!(password.equals("LipSmacker")))
{
if ( counter == 3)
{
System.out.printf("Sorry, invalid password! No more attempts left. Exiting program.");
counter = 5;
}
else
{
System.out.printf("\n\nInvalid password you have %d attempts left", attempt);
attempt = attempt - 1;
}
}
else
{
counter = 4;
System.out.printf("Enter your Banner ID: ");
bannerID = input.nextLine();
System.out.printf("Enter your Name: ");
studentName = input.nextLine();
System.out.printf("Enter your course: ");
course = input.nextLine();
System.out.printf("How many grades will be entered? ");
gradesAttempt = input.nextInt();
do
{
System.out.printf("\nPlease enter grade no %d: " ,counterGradeAttempt);
grades = input.nextInt();
gradesTotal += grades;
counterGradeAttempt = counterGradeAttempt + 1;
average = gradesTotal / gradesAttempt;
switch ((int)average )
{
case 10: letterGrade = "A";
break;
case 9: letterGrade = "A";
break;
case 8: letterGrade = "B";
break;
case 7: letterGrade = "C";
break;
case 6: letterGrade = "D";
break;
}
} while ( counterGradeAttempt <= gradesAttempt);
System.out.printf("STUDENTS CURRENT GRADE FOR %s" ,course);
System.out.printf("\n\nBanner ID: %s" ,bannerID);
System.out.printf("\nStudent Name: %s" ,studentName);
System.out.printf("\nAverage of grades: %.2f" ,average);
System.out.printf("\nLetter grade: %s " ,letterGrade);
}
}
System.exit(0);
}
} //END MAIN()
I cant get the letterGrade to print out
Re: letterGrade not print out on my code
figured it out, the switch need to be / 10.
Re: letterGrade not print out on my code
Quote:
letterGrade not print out on my code
A problem would be that you have no default: case in the switch statement to print out a message about the value of average. Your code should try to handle ALL the legal possibilities.
Re: letterGrade not print out on my code
True, but still that was not the case, the average was apparently to high for the switch cases, so I had to take them down a notch.
Re: letterGrade not print out on my code
Quote:
average was apparently to high for the switch cases
It would NOT be too high for the default. The message that would print there would tell you the problem the first time you ran the code.