I want the program to only allow integers at certain points. The code works but I have to enter a value twice then it skips a part of my code.
My code is
`
case 1:
char ans;
do{
Event event = new Event();
out.println("Please Enter the name of event");
event.setEvent(input.next());
input.nextLine();
do{
try{
out.println("Please Enter the price of this event\n");
event.setprice(input.nextDouble());
}catch (InputMismatchException e){
out.println("Please Enter the price of this event\n");
}
input.nextLine();
} while (! input.hasNextDouble());
out.println("Please Enter the date of this event\n");
event.setdate(input.next());
out.println("Please enter the amount of tickets available for this event.\n");
event.setavailability(input.nextInt());
out.println("Please enter the venu");
event.setvenue(input.next());
Events.add(event);
out.println("Would you like to add a new event?");
String answer = input.next();
ans = answer.charAt(0);
}while (ans == 'y');
out.println(Events.get(0));
break;
the problem with this is it displays like this:
1
Please Enter the name
red
Please Enter the price of this event
40
40
Please Enter the date of this event
Please enter the amount of tickets available for this event.
40
It doesn't allow me to enter the date and I have to enter the price value twice
Any help and advice would be great.
Thanks