Question: The Event.java and EventDemo.java manage the number of admitted guests to a social event. There is a maximum number of guests that can be admitted

The Event.java and EventDemo.java manage the number of admitted guests to a social event. There is a maximum number of guests that can be admitted to the event. This number is given to the Event.java constructor as a parameter. In the EventDemo.java this value is currently set to 10.

1- Complete the Event.java and EventDemo.java classes such that when you run the EventDemo.java, the following output is generated.

Please note that EventDemo.java should be able to catch the Exception.

The program output:

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; } public void admitOneGuest() { //Complete this method } public int getNumberOfAdmittedGuests() { //Complete this method } } 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 <= MAX_NUMBER_OF_ADMITTIONS; i++) { { event.admitOneGuest(); System.out.println(event.getNumberOfAdmittedGuests() + " Guest(s) Admitted."); } (CapacityFullException e) { System.out.println("Event Sold Out! " ); break; } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!