here is what i am required to do here:
Write a program that prompts a professor to input grades for different course for 10 students. Prompt the professor to enter one grade at a time using the prompt � Enter name for student # 1� and �Enter grade #1.� Verify that the professor enters only A, B, C, D, or F. use variables for the student numbers (1 through 10) and grade numbers (1 through 5).
import java.io.*;
class name_and_grade
{
static char grade;
static void get_name() throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String name;
System.out.println("Enter Name");
name = in.readLine();
}
static void get_grade()
{
try
{
System.out.println("Enter Grade");
grade = (char)System.in.read();
verify_grade();
}catch(Exception E)
{
System.out.println("Erroe");
}
}
static void verify_grade()
{
if(grade != 'A' || grade != 'B' || grade != 'C' || grade != 'D' || grade != 'F')
{
System.out.println("Grade has to be eithe A, B, C, D, or F");
}
}
public static void main(String args[]) throws IOException
{
for(int i=1; i<=10; i++)
{
get_name();
get_grade();
}
}
}
i don't get any errors when i compile this code.
Out put after entering 1st Name and 1st Grade:
Enter Name
Tony
Enter Grade
A
Grade has to be eithe A, B, C, D, or F
Enter Name
Enter Grade
my question is why it is showing this message(Grade has to be eithe A, B, C, D, or F) even the grade i entered was 'A'.
and after that message it skips where i am supposed to enter name and jumps to enter grade part.
why is so?
thanks