A small theatre on campus can seat 100 in a 10 rows each having 10 seats arrangement. Tickets are assigned to seats based on their location in the seating map. The following depicts this arrangement, the numbers represent ticket numbers associated with seats.
| 1 2 3 4 5 11 12 13 14 15 | 6 7 8 9 10 16 17 18 19 20 |
| . . 91 92 93 94 95 | . . 96 97 98 99 100 |
So based on this chart, ticket #15 will be associated with the seat on row 2 and column 5. The seating chart is consisted of four zones: each zone will be a 5 by 5 section. The zones are defined as follows:
Upper_Left defined as UL: rows 1 – 5, columns 1 – 5
Upper_Right defined as UR: rows 1 – 5, columns 6 – 10
Lower_Left defined as LL: rows 6 – 10, columns 1 – 5
Lower_Right defined as LR: rows 6 – 10, columns 6 – 10
As part of operations for this facility, staff must keep track of which seat is occupied, how many tickets are sold, how many students are sitting next to each other, how request for seat change will be handled, how they can swap rows of seats, how they can specify tickets sold on different zones, etc. So you are asked to write a program to allow such operations.
Here are the REQUIRED COMPONENTS of this program:
class Ticket: Use proper access modifiers in your program:
Attributes:
Status is an enum type consisting of constants STUDENT and NON_STUDENT. int ticketNumber;
Status ticketStatus;
Methods:
• Define a constructor that initializes all these attributes. It should receive exactly TWO arguments.
• Define all the set and get methods.
• Define the toString method to generate an output that reads (check pg 332):
Ticket: [Ticket#: 5] [Status: Student]
class Seat: Use proper access modifiers in your program:
Attributes:
int row; int column;
Ticket seatTicket;
The Seat class is also going to have an attribute of type Zone that is an enum type that is defined in class Theatre, let’s call this attribute seatZone. You have to declare this attribute considering that its type should be accessed properly. We leave this declaration for you to complete!
??? seatZone; // Which will be one of: UL, UR, LL, LR
Methods:
• Define a constructor that receives ONLY ONE argument: a Ticket object. It initializes the seatTicket attribute to this argument. But it also uses the ticketNumber attribute of this object to compute the row and the column and initializes them to those values.
Notice that in order to compute the row and column based on the ticket number, you have to study the pattern of numbering within this 2d structure. It only takes simple arithmetic operations to get from a ticket number to its actual coordinates in the seating chart.
The constructor should also compute the zone for this seat. Use the specifications of zones given at the beginning of this document to assign the proper zone for seatZone attribute. Once again you have to pay attention to your access to this enum type as well as its predefined constants, within this class.
• Define an overloaded constructor (pg 338) that receives FOUR arguments: row, column, zone and Status. This constructor will be used when a user wants to buy a ticket in a special zone. This constructor needs to do the following:
• Use the row and column to compute the ticket number. This process will be the reverse of what you did to get to the row and column based on the ticket number.
• The constructor receives the user status, so the ticketStatus will be initialized to this argument.
• At this point the Seat constructor is ready to issue a ticket, i.e. instantiate a Ticket object. So it does so, and initializes its seatTicket attribute to this object.
• The constructor also receives the zone as an argument so it initializes the
seatZone attribute to this argument as well.
• Define all the set and get methods.
• Define the toString method to generate an output that reads (pg 332):
Seat: [Row: 1] [Column: 5] [Zone: UL] Ticket: [Ticket#: 5] [Status: Student]
You must have noticed that the second line of the above output can be generated by Ticket object’s toString method. Are you going to take advantage of this? Could you?
class Theatre: Use proper access modifiers in your program:
Attributes:
Zone is an enum type consisting of constants UL, UR, LL, LR. seatingChart: A 2d array of type seatof size 10 by 10 (pg. 286).
Methods:
• Define a constructor that receives an integer indicating how many seats will be instantiated randomly. So it sets up a loop based on that number, to do the following:
1. Randomly generate a ticket number in the range 1 – 100 (pg. 226).
2. Randomly pick a status either STUDENT or NON_STUDENT. Please note that this enum type is part of class Ticket, you should pay attention to how to access this type as well as its constants in this class.
3. Use the above two values to instantiate a Ticket object.
4. Use the above Ticket object to instantiate a Seat object (An example of composition). Notice you are using the first of two overloaded constructors here. You are passing a single argument to this constructor. We know that as a result of this constructor the row and column attributes of the Seat object will be computed. This is what you take advantage of in the next step.
5. Use the getRow and getColumn methods of the above Seat object to store this object in the 2d array seatingChart. Please pay attention that the rest of the elements in this 2d array will remain null.
• Define a displayTheSeatingChartmethod that outputs the entire seating chart: 0’s for null/non-instantiated seats and ticket numbers for occupied/ instantiated seats.
• Define a displayTheZonemethod that outputs the specified zone. This method should receive a single argument of type Zone.
Important note on your displaymethods: Since we leave the unoccupied seats as null, you need to make sure that your loop does not attempt to treat nulls as objects.
• Define a method called swapTheSeats that receives two integers representing two ticket numbers. Note: You do not need to validate these ticket numbers. The assumption would be that they already exist in your seating chart. This method swaps the two Seat objects without changing the ticket numbers or the values for the object’s row and column attributes. The method outputs a message such as:
Seats with ticket numbers 13 and 22 are now swapped.
• Define a method called swapTheRows that receives two integers representing two row numbers. Note: You do not need to validate these row numbers. We are simply going to trust the user! This method swaps the two rows without changing the any values in their respective seat objects’ attributes. The following could be an example of the message outputted by this method:
Rows numbers 2 and 3 are now swapped.
• Define a method called cancelTheSeatthat receives a ticket number, validates the ticket number by looking for it in the seating chart, if not found outputs a proper message such as:
No seat reservation for number 22 is found.
And if found, it should nullify the seat object, and output a message such as:
Your seat reservation number 22 is canceled.
• Define a method called reportSales that outputs the total number of tickets sold to STUDENTS and NON_STUDENTS respectively. This is a void method and does not receive any arguments.
THE BONUS SECTION 30 points
The following is requirements for option 6 and 7 that is a BONUS option. We strongly recommend trying to work on these options:
• Define a method called whatZone that receives two arguments: the numbers for the row and the column. It then returns the zone for that specific coordinates. This method will be called in the following method bookByRow.
• Define a method called bookByRow that receives user’s choice for a row. This method should search that row in the 2d array to find a vacant seat (i.e. null). If it finds one, it will call the whatZonemethod to determine the zone for that seat. It now can use the row number, the column number, the zone and the user-specified status to instantiate the seat object using the proper overloaded constructor, and
store that object in the available spot. This method will call the toStringmethod of the newly instantiated Seat object to display the following message:
We reserved your seat. This is the information:
Seat: [Row: 1] [Column: 5] [Zone: UL] Ticket: [Ticket#: 5] [Status: Student]
If the row is completely full, this method need to output a proper message indicating so, for example:
The row 1 is completely full.
• Define a method that collects occupancy data on each of the four zones and return the zone with the highest number of seats occupied. This is a BONUS option aswell.
END OF BONUS SECTION
class TheatreTest This is your driver class
In main method:
• Prompt the user for how many tickets they would like to randomly issue.
• Instantiate an object of type Theatrepassing the user input to its constructor.
Display the following menu:
1. Display the seating chart of the theatre.
1. The entire chart.
2. Specific zone.
Please choose the zone:
1. UL 2. UR 3. LL 4. LR
2. Swap two seats
Please enter the ticket numbers, press enter after each entry.
3. Swap two rows.
Please enter the row numbers (1-10), press enter after each entry.
4. Cancel a booking.
Please enter your ticket number.
5. Total number of STUDENT and NON_STUDENT tickets sold?
THE BONUS OPTIONS
6. BONUS: Book a ticket based on a row:
1. Please enter the row number (1-10):
2.What is your status:
1. STUDENT 2. NON_STUDENT
7. BONUS: Which zone has the highest occupancy?
END BONUS OPTIONS
8. Exit
The following is a suggestion of the interface for the driver class (TheatreTest) illustrating the user interface and the main menu options:
The following is more explanations on the menu options:
Option 1: You MUST CALL either the displayTheSeatingChart or displayTheZone for this option based on the input you read on submenu items. Please format your output in terms of spacing for a more organized display of your 2d array(s).
Option 2: You MUST CALL method swapTheSeats for this option.
Your program should output a message indicating that the swap was completed Again we acknowledge the disrupt of seat location and ticket number correlation asa result of any swaps. Again this means that you do not change the ticket numbers as a result of this swap.
Option 3: You MUST CALL method swapTheRows for this option. Your program should output a message indicating that the swap was completed. For this option, you should take advantage of the fact about how 2d arrays are configured in memory in Java: an array of arrays. Do you see how this provides for a very easy swap of rows? Are rows not just single reference variables in the row array?
We should acknowledge that this swap disrupts the logical correlation between the ticket number and the coordinates (row, col) of the row seats. But we allow this for the purpose of practicing with index manipulations. This means that you do not change the ticket numbers as a result of this swap.
Option 4: You MUST CALL cancelTheSeatmethod here. Remember this method MUST validate the ticket number.
Option 5: You MUST CALL reportSales method here.
The post A small theatre on campus appeared first on My Assignment Online.