Currently programming an interactive program for class in Java; it's a menu with 5 different choices(0-4) through a switch statement. When started, a Scanner takes in whichever the choice is and executes one of five different methods.
case 2:
System.out.println("Choose where you want to put the student");
int id2 = scan.nextInt();
AddStudent(id2);
ViewStudents("all");
break;
Which calls AddStudent:
private void AddStudent(int id) {
System.out.println("Type in name, subject and mark: ");
String name = scan.nextLine();
String subject = scan.nextLine();
int mark = scan.nextInt();
/* check via loop studentNames array and if it's null at
[i], set studentNames[i] to name,
studentSubjects[i] to subject and studentMarks[i] to mark.
*/
for (....) {
if (studentNames[i] == null) {
studentNames[i] = name;
}
}
But when I run this method I don't get to input the three scan instances. I get a InputMismatchException. How do I work around this?