This is a question on my study guide. I am not understanding switches very well.
The questions says a professor determines his grades based on the following table.
score
90-100
80-89
70-79
60-69
<60
grade
A
B
C
D
F
Assign the appropriate value to the variable grade(character) based on the variable score(integer). Use the switch structure.
We were told you are not supposed to use relational operators in JAVA in a switch (char or int).
My thoughts would have been
{
case 1: Grade = "A";
break;
case 2: Grade = "B";
break;
case 3: Grade = "C";
break;
case 4: Grade = "D";
break;
default:
Grade = "F";
}
I just don't know how to work in the grade scale. Any help appreciated.
Comments
The answer is not obvious, but a similar problem is shown [link=http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html]here[/link] with the SwitchDemo2 program. There will be a case statement for each possible grade.