Question: Java Help: Question 2- In Question2 folder, the Event.java and EventDemo.java classes manage the number of admitted guest to an event. The maximum number of
Java Help:
Question 2- In Question2 folder, the Event.java and EventDemo.java classes manage the number of admitted guest to an event. The maximum number of admissions is given to the Event.java class constructor as a parameter, which is currently set to 10. Complete the Event.java class such that when you run the EventDemo.java, the following output is generated. Please note that the EventDemo.java class is already complete and you should not change it. Also, you may need to add one or more new classes. >javac EventDemo.java The command on the command line to compile the program >java EventDemo The command on the command line to run the program 1 Guest(s) Admitted. 2 Guest(s) Admitted. 3 Guest(s) Admitted. 4 Guest(s) Admitted. 5 Guest(s) Admitted. 6 Guest(s) Admitted. 7 Guest(s) Admitted. 8 Guest(s) Admitted. 9 Guest(s) Admitted. 10 Guest(s) Admitted. Event Sold Out! CapacityFullException: Max Number of Guests of 10 Reached
//Event
public class Event{
private int maxCapacity; private int numberOfAdmittedGuests;
public Event(int maxCapacity){ this.maxCapacity = maxCapacity; numberOfAdmittedGuests = 0; } }
//Event Demo
public class EventDemo {
private static final int MAX_NUMBER_OF_ADMITTIONS = 10;
public static void main(String[] args){ Event event = new Event(MAX_NUMBER_OF_ADMITTIONS); for (int i = 0; i < 100; i++){ try{ event.admitOneGuest(); System.out.println(event.numberOfAdmissions() + " Guest(s) Admitted."); } catch(CapacityFullException e){ System.out.println("Event Sold Out! " + e); break; } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
