This is for coursework. I’ve built the whole program, and it does everything right, apart from this one thing.
I have a class called ‘Schedule’ this method is at the very end of schedule:
public void bookSeatMenu()
{ boolean leaveBookSeatMenu = false;
String seatBookingMenuStr;
int seatBookingMenuInt = 14;
boolean isInteger = false;
Scanner input = new Scanner(System.in);
System.out.println("Press 1 to add an individual booking, 2 to cancel a booked seat or 3 to go back");
seatBookingMenuStr = input.nextLine();
try {
seatBookingMenuInt = Integer.parseInt(seatBookingMenuStr);
isInteger = true;
}
catch (NumberFormatException e) {
}
switch (seatBookingMenuInt) {
case 1:
bookSeat();
break;
case 2:
cancelSeat();
break;
case 3:
leaveBookSeatMenu = true;
break;
default:
System.out.println("Invalid Choice");
} while (leaveBookSeatMenu == false);
}
I know you all know what a switch menu looks like, but I thought I’d throw it in there anyway, in case (pardon the pun) I’m going wrong here.
Moving on, I have the bookSeat method, this is where the user books a seat (which works fine). Then afterwards it displays the bookSeatMenu() just it displays the menu. But then it won’t go back to the previous one.
public void bookSeat()
{
Scanner input = new Scanner(System.in);
boolean isSeatBooked = true;
showSeatPlan();
int seatNum = 0;
int rowNum = 90;
int columnNum = 16;
boolean isInt = false;
while (isSeatBooked == true)
{
System.out.println("Please pick column of a seat to book");
columnNum = input.nextInt();
System.out.println("Please pick row of a seat to book");
rowNum = input.nextInt();
seatNum = (columnNum + ((rowNum) * 15));
if (seats[seatNum] == false)
{
isSeatBooked = false;
}
else
{
System.out.println("This seat is already booked");
}
}
seats[seatNum] = true;
System.out.println("");
bookSeatMenu();
}
Now not for love nor money am I able to get it to go back to the previous menu after it’s booked a seat.
Basically the process is:
Book a seat –> go to bookSeatMenu –> press 4 to go back –> Arrive at previous menu.
If I don’t book a seat, the program will happily go back to the menu before hand, but after, it just keeps on going on to a new line in the command prompt, not doing anything else, no error etc.
I’m pretty tempted to say this might be a problem with BlueJ, although a bad workman blames his tools, and I don’t wanna be ‘that guy’
I also need to make a ‘testing class’ – having never used a ‘testing class’ before, and the assignment asking us to look in the ‘textbook’ which noone bothered to buy, I actually have no idea!
There’s no
switch...whileso I assume your problem is as soon you do choose 3, you end up inwhile(true);which is an infinite loop.correct pseudo-code:
By the way, design is bad IMHO, you should try to think about your model (in your case I would see something like
Room,Seat,Scheduler,Menu) and make those object interact with each others :(something like that)
For the test part, each class have a test class and each method have a test method, as an example, for
Seat: