I am working on a homework assignment. The assigntment info is as follows:
Write a grading program that helps to determine your letter grade based on your exam score. For example, when you put in exam score of 80, the program will determine you get a B. Please note the following:
1) Your letter will be determined by only one exam score.
2) The program will keep on prompting you to put more scores until you hit the E button on your keyboard.
3) The scoring standard:
A 90 – 100
B 80 – 89
C 70 – 79
D 60 – 69
F Below 60
Here is my coding:
import java.util.Scanner; // needed for Scanner class
public class LetterGrade {
public static void main(String[] args){
String userInput; // To hold the user's input
int letterGrade; // The user's letter grade
boolean moreGrade = true;
while (moreGrade){
System.out.print("Please enter a score or press E to exit the program ");
// create Scanner object for keyboard entry
Scanner keyboard = new Scanner(System.in);
userInput = keyboard.nextLine();
letterGrade = userInput.charAt(0);
if ((letterGrade >= 90) & (letterGrade <= 100)) {
System.out.println("The letter grade is A");
} else if ((letterGrade >= 80) & (letterGrade < 90)){
System.out.println("The letter grade is B");
} else if ((letterGrade >= 70) & (letterGrade < 80)) {
System.out.println("The letter grade is C");
} else if ((letterGrade >= 60) & (letterGrade < 70)) {
System.out.println("The letter grade is D");
} else if ((letterGrade >= 0) & (letterGrade < 60)) {
System.out.println("The letter grade is F");
} else if (letterGrade == 'E' || letterGrade == 'e'){
System.out.println("Thank you for using the grading system");
moreGrade = false;
} else {
System.out.println("That was an invalid entry, please try again");
}
}
}
}
I am having a couple of issues here.
1) No matter what score I enter it always prints "The letter grade is F."
2) When I enter "E" it prints "The letter grade is D", but if I enter "e" the program exits.
Here is what it looks like when I run the program:
Please enter a score or press E to exit the program 98
The letter grade is F
Please enter a score or press E to exit the program 88
The letter grade is F
Please enter a score or press E to exit the program 77
The letter grade is F
Please enter a score or press E to exit the program 65
The letter grade is F
Please enter a score or press E to exit the program 54
The letter grade is F
Please enter a score or press E to exit the program E
The letter grade is D
Please enter a score or press E to exit the program e
Thank you for using the grading system