Question: Notes: Assume that the classes listed in the Quick Reference have been imported where needed. Unless otherwise noted in the question, assume that parameters in
Notes:
-
Assume that the classes listed in the Quick Reference have been imported where needed.
-
Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
-
In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods may not receive full credit.
The TicketAssignment interface below represents ticket assignments that can be used to assign tickets for some live event. This question involves writing a class that will be used to generate ticket assignments.
public interface TicketAssignment {
/** Returns current ticket assignment */
String getTicket();
/** Changes to the next ticket assignment */
void nextTicket();
}
The SeatAssignment class is a TicketAssignment that generates seat assignments. A SeatAssignment object is constructed with: a letter, hyphen, and starting integer. The letter (used to designate the row) and hyphen remain constant in every seat assignment. The starting integer is used as the starting value for the seat number within the row. The integer is incremented for each seat in the row by the class.
As an example, a SeatAssignment object created with the call new SeatAssignment(A, 7) would be used to generate the seat assignments "A-7", "A-8", "A-9", etc.
In the SeatAssignment class, the getTicket method returns a string in the format of "letter - integer". The nextTicket method updates the state of the SeatAssignment object to represent the next seat in the row. The example below shows how the SeatAssignment class works.
| Code | Seat Assignment |
| TicketAssignment t1 = new SeatAssignment(A, 7); System.out.println(t1.getTicket());
t1.nextTicket(); System.out.println(t1.getTicket()); t1.nextTicket(); System.out.println(t1.getTicket()); | A-7
A-8 A-9 |
Write the complete SeatAssignment class. Your implementation should be consistent with the requirements and example above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
