Exercise #5
The Ticket Machine
For the upcoming concert, write a program that simulates an automatic ticket-vending machine. Your task for the exercise is to assign seat numbers to the tickets. Seats are numbered starting at 1 and increase from there. Assume there is no maximum number of seats (i.e. seat numbers can be assigned without hitting some capacity).
Here is an example of the desired program in operation:
If the customer only wants one ticket and clicks on the "Buy" button then the customer should get seat number 1. The program should output the range of seats that have been assigned to his or her ticket:
If the next person wants 3 tickets then seats 2-4 should be assigned, since seat 1 went to the first customer:
If the next person wants 2 seats then seats 5-6 should be assigned, etc.
This exercise is intended to illustrate how class level variables are used. You should store the number of the next seat to be assigned as a class level variable (initially set to 1). By making it a class level variable it will retain its value as long as the program is running. If this number was declared inside the button click method then it would be re-created every time the button is clicked. When the button is clicked, the customer should be assigned seats in the range from (next seat number) to (next seat number + number of tickets purchased - 1). The number of tickets purchased should then be added to the number of the next seat in preparation for the next customer.