Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions