public class Patron { public int age; public Ticket ticket; public Patron(int anAge) { age = anAge; ticket = null; } public String toString() { String result = age + "yr old patron with"; if (ticket == null) return result + "out a ticket"; return result + " a ticket for theatre " + ticket.theatreID; } // Determine and return the price that the Patron should pay for a ticket public float ticketPrice() { if (age <= 12) return Ticket.REG_CHILD_PRICE; else if (age >= 65) return Ticket.REG_SENIOR_PRICE; return Ticket.REG_ADULT_PRICE; } // Simulate this patron buying a ticket at a theatre public void buyTicket(Theatre aTheatre) { if (aTheatre.seatsSold < aTheatre.capacity) { ticket = new Ticket(aTheatre.id); // make and store the ticket // Now increase the earnings and add 1 to the count of seats sold aTheatre.movieEarnings += ticketPrice(); aTheatre.seatsSold++; } } // Simulate this patron returning a ticket for a theatre public void returnTicket(Theatre aTheatre) { if ((ticket != null) && (ticket.theatreID == aTheatre.id)) { ticket = null; // Now decrease the earnings and deduct 1 from the count aTheatre.movieEarnings -= ticketPrice(); aTheatre.seatsSold--; } } }