vendredi 5 juin 2020

Beginner question: While loop with if statement inside

So I've been working on this lab for awhile. I'm in the worst class of all time and am basically learning java on my own. This bit of code is not working properly, as the result looks as shown here. It's supposed to take a student's name, then which test, then the grade. It runs through correctly the first time and then says "Enter student name: Which test?" the second time. It's not allowing for input of "student name" after the first loop. What am I doing wrong here? I'm super frustrated

public void inputGrades()
    {
            // Grade input
        Scanner input = new Scanner(System.in);
        System.out.print("\nEnter 'quit' when done entering names and grades. \nEnter student name: ");
            name = input.nextLine();

        System.out.print("Which test? ");
            grade = input.nextLine();

                    // Grades for test 1
        while (!(name.equalsIgnoreCase("quit")))
        {
            if (grade.equalsIgnoreCase("Test 1"))
            {
                System.out.print("Enter grade: ");
                gradeTest1 = (double) input.nextDouble();
            }

                    // Grades for test 2
            else if (grade.equalsIgnoreCase("Test 2"))
            {
                System.out.print("Enter grade: ");
                gradeTest2 = input.nextDouble();
            }

            System.out.print("\nEnter 'quit' when done entering names. \nEnter student name: ");
                name = input.nextLine(); 

            System.out.print("Which test? ");
                grade = input.nextLine();
        }
    }   

Aucun commentaire:

Enregistrer un commentaire