I dont have any errors now in the code but after it runs I get an error when running it,problem with the scanner and int.
Please choose and option:[1-4].
1 - Add a Student.
2 - Delete a Student.
3 - List all Students.
4 - Exit.
1
Please enter no of students lkmskfn
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at StudentMenu.main(StudentMenu.java:31)
import java.util.ArrayList;
import java.util.Scanner;
public class StudentMenu
{
public static void main ( String[] args )
{
ArrayList<Student> studentlist = new ArrayList<Student>();
Student nextStudent;
int select;
String fName;
String sName;
String grade;
int mark;
do
{
System.out.println ( "Please choose and option:[1-4].\n" +
"1 - Add a Student.\n" +
"2 - Delete a Student.\n" +
"3 - List all Students.\n" +
"4 - Exit." );
Scanner keyboard = new Scanner ( System.in );
select = keyboard.nextInt();
switch ( select )
{
case 1:
System.out.print ( "Please enter no of students " );
int numstudents = keyboard.nextInt();
keyboard.nextLine();
for ( int i = 0; i < numstudents; i++ )
{
System.out.print ( "Please enter students first name: " );
fName = keyboard.nextLine();
System.out.println();
System.out.print ( "Please enter students surname: " );
sName = keyboard.nextLine();
System.out.println();
System.out.print ( "Please enter your exam mark: " );
mark = keyboard.nextInt();
System.out.println();
nextStudent = new Student ( fName, sName, mark );
studentlist.add ( nextStudent );
}
break;
case 2:
{
System.out.print ( "Please enter student you want to delete first name: " );
fName = keyboard.next();
System.out.println();
System.out.print ( "Please enter students surname: " );
sName = keyboard.next();
System.out.println();
for ( Student s : studentlist )
{
if ( ( s.getFname().equals ( fName ) ) && ( s.getSname().equals ( sName ) ) )
{
studentlist.remove ( s );
}
}
}
break;
case 3:
{
for ( Student s : studentlist )
{
System.out.println ( s );
}
}
break;
case 4:
{
System.out.println ( "Goodbye" );
}
{
Default:
{
System.out.println ( "Invalid Selection, Plaese try again" );
}
break;
}
}
}
while ( select != 4 );
} // end method main()
} // end class StudentMenu