public class TheatreSimulatorProgram { // Simulate the opening of a movie to a theatre public static void openMovie(Theatre aTheatre, String newMovie) { aTheatre.moviePlaying = newMovie; aTheatre.movieEarnings = 0; aTheatre.seatsSold = 0; aTheatre.admittedPatrons = 0; } // Simulate a patron entering a theatre public static void admit(Patron aPatron, Theatre aTheatre) { if ((aPatron.ticket != null) && (aPatron.ticket.theatreID == aTheatre.id)) { aPatron.ticket = null; aTheatre.admittedPatrons++; } } // Determine and return the price that the given Patron should pay for a ticket public static float priceFor(Patron p) { if (p.age <= 12) return Ticket.REG_CHILD_PRICE; else if (p.age >= 65) return Ticket.REG_SENIOR_PRICE; return Ticket.REG_ADULT_PRICE; } // Simulate a patron buying a ticket at a theatre public static void buyTicket(Patron aPatron, Theatre aTheatre) { if (aTheatre.seatsSold < aTheatre.capacity) { Ticket t = new Ticket(aTheatre.id); // make the ticket aPatron.ticket = t; // store the ticket // Now increase the earnings and add 1 to the count of seats sold aTheatre.movieEarnings += priceFor(aPatron); aTheatre.seatsSold++; } } // Simulate a patron returning a ticket for a theatre public static void returnTicket(Patron aPatron, Theatre aTheatre) { if ((aPatron.ticket != null) && (aPatron.ticket.theatreID == aTheatre.id)) { aPatron.ticket = null; // Now decrease the earnings and deduct 1 from the count aTheatre.movieEarnings -= priceFor(aPatron); aTheatre.seatsSold--; } } // The program starts here public static void main(String args[]) { // Make a couple of theatres Theatre t1 = new Theatre('A', 3); // capacity = 3 Theatre t2 = new Theatre('B', 10); // Make a few of patrons Patron adam = new Patron(10); Patron biff = new Patron(17); Patron chad = new Patron(21); Patron dana = new Patron(73); System.out.println("Theatre 1 capacity: " + t1.capacity); System.out.println("Theatre 1 seats sold: " + t1.seatsSold); System.out.println("Theatre 1 opening Movie ... \"Jurassic World\""); openMovie(t1, "Jurassic World"); System.out.println("Theatre 1 earnings: " + t1.movieEarnings); System.out.println("10 year old buying a ticket ... "); buyTicket(adam, t1); System.out.println(adam); System.out.println("17 year old and 21 year old buying tickets ... "); buyTicket(biff, t1); buyTicket(chad, t1); System.out.println("Theatre 1 seats sold: " + t1.seatsSold); System.out.println("Theatre 1 earnings: " + t1.movieEarnings); System.out.println("10 year old returning a ticket ... "); returnTicket(adam, t1); System.out.println("Theatre 1 seats sold: " + t1.seatsSold); System.out.println("Theatre 1 earnings: " + t1.movieEarnings); System.out.println(adam); System.out.println("73 year old buying a ticket ... "); buyTicket(dana, t1); System.out.println(dana); System.out.println("Theatre 1 seats sold: " + t1.seatsSold); System.out.println("Admitting 17 year old into theatre ... "); admit(biff, t1); System.out.println(biff); System.out.println("Admitting 21 year old into wrong theatre ... "); admit(chad, t2); System.out.println(chad); System.out.println("Theatre 2 admitted patrons: " + t2.admittedPatrons); System.out.println("Admitting 21 year old into correct theatre ... "); admit(chad, t1); System.out.println("Theatre 1 admitted patrons: " + t1.admittedPatrons); System.out.println("Admitting 73 year old into theatre 1 ... "); admit(dana, t1); System.out.println("Theatre 1 admitted patrons: " + t1.admittedPatrons); System.out.println("Attempt to admit 10 year old into theatre 1 ... "); admit(adam, t1); System.out.println("Theatre 1 admitted patrons: " + t1.admittedPatrons); System.out.println("Theatre 1 earnings: " + t1.movieEarnings); } }