/* Program BookingSystem to test the class FilmTheatre. * * Carsten Butz, October 2002. */ import tio.*; class BookingSystem{ public static void main(String[] args) throws NotASeatException { int choice; FilmTheatre ft = new FilmTheatre(8,10); do{ /* Read input and handle it. */ choice = menu(); switch(choice){ case 1: makeReservation(ft); break; case 2: makeCancelation(ft); break; case 3: isReserved(ft); break; case 4: ft.findSeat(); break; case 5: System.out.println("There are "+ft.numReservations()+" reservation(s).\n"); break; case 6: ft.showReservations(); break; case 7: break; default: System.out.println("Please enter a number between 1 and 7."); } } while(choice != 7); System.out.println("Thank you for using our booking system!"); } static int menu() { int input = 0; System.out.println("Type"); System.out.println("1 for a reservation"); System.out.println("2 to cancel a reservation"); System.out.println("3 to find out whether or not a seat is available"); System.out.println("4 to find the next available seat"); System.out.println("5 to get the number of reservations"); System.out.println("6 to view the film theatre"); System.out.println("7 to quit"); input = Console.in.readInt(); return input; } static int inputData(){ int data = 0; data = Console.in.readInt(); return data; } static void makeReservation(FilmTheatre ft) throws NotASeatException { int row, seat; System.out.print("Please enter the row number: "); row = inputData(); System.out.print("Please enter the seat number: "); seat = inputData(); if(!ft.reserve(row,seat)) System.out.println("This seat was not booked!"); return; } static void makeCancelation(FilmTheatre ft) throws NotASeatException { int row, seat; System.out.print("Please enter the row number: "); row = inputData(); System.out.print("Please enter the seat number: "); seat = inputData(); if(!ft.cancel(row,seat)) System.out.println("This seat was not booked!"); return; } static void isReserved(FilmTheatre ft) throws NotASeatException { int row, seat; System.out.print("Please enter the row number: "); row = inputData(); System.out.print("Please enter the seat number: "); seat = inputData(); if(ft.isReserved(row,seat)) System.out.println("This seat is booked!"); return; } }