2. The EventTracker class, which you will write, represents an event attendance system. EventTracker objects are created by calls to a constructor with two parameters.
EventTracker objects are created by calls to a constructor with two parameters.
The first parameter is a String that represents the name of the event. (Precondition: Assume that this value is not null.)
The second parameter is an int that represents the maximum capacity of the event. (Precondition: Assume that this value will be greater than 0.)
enter
The EventTracker class contains an enter method, which processes a group of people attempting to enter the event.
The method takes a single int parameter representing the number of people attempting to enter. Assume this value is greater than 0.
The method calculates how many people can enter without exceeding the event's capacity.
If the number of people attempting to enter is less than or equal to the available space, all of them enter, and the method updates the current attendance.
If the number of people attempting to enter exceeds the available space, the attendance is filled to the capacity, and the remaining people are turned away.
The method returns an int representing the number of people who were turned away (0 if everyone entered).
Returns the number of people turned away (int)
stats
The EventTracker class contains a stats method, which returns a string summary of the event status.
The method takes no parameters.
The method returns a String containing the event name, current attendance, and capacity in the format "Name: current/capacity".
If the event is at full capacity (current attendance equals capacity), the string " (FULL)" is appended to the end of the status string.
Returns a formatted String representing the event status
Statement | Return Value (blank if no value) | Explanation |
|---|---|---|
EventTracker e = new EventTracker("Gala", 100); | EventTracker e is constructed with name "Gala" and capacity 100. Current attendance is 0. | |
e.stats(); | "Gala: 0/100" | Returns the status. No one has entered yet. |
e.enter(80); | 0 | 80 people attempt to enter. There is space for 100. All 80 enter. 0 are turned away. Attendance is now 80. |
e.stats(); | "Gala: 80/100" | Returns the updated status. |
e.enter(30); | 10 | 30 people attempt to enter. There is only space for 20 (100 - 80). 20 enter, filling the event. 10 are turned away. Attendance is now 100. |
e.stats(); | "Gala: 100/100 (FULL)" | Returns the status. Because attendance equals capacity, " (FULL)" is appended. |
e.enter(5); | 5 | 5 people attempt to enter. The event is full. 0 enter. All 5 are turned away. |
Write the complete EventTracker class. Your implementation must meet all specifications and conform to the examples shown in the table.
00:00