Im creating a lift simulation but am having trouble with the error handling. When a user inputs a letter instead of a integer it throws a InputMismatchException. How do i fix this? Here is the code below:
System.out.println("Please define... ");
System.out.println("Number of floors:");
Building building = new Building(in.nextInt());
System.out.println("Number of lifts:");
building.setNoOfLifts(in.nextInt());
building.setLifts();
System.out.println("Maximum number of people to enter building at one time:");
building.setMaxPeople(in.nextInt());
System.out.println("Maximum capacity of the lifts:");
int maxLiftCapacity = in.nextInt();
System.out.println("Simulation will now begin.");
Queue queue = new Queue();
When a user inputs a letter instead of a integer it throws a InputMismatchException. How do i fix this?You could cuss him out or threaten dire consequences. But you may just want to usetry { ...} catch(InputMismatchException e) { ...}around your code.