Question: 1. Creating a Superclass: Create the general Party class: The class hosts one integer data fieldthe number of guests expected at the party: private int

1. Creating a Superclass:

Create the general Party class:

The class hosts one integer data fieldthe number of guests expected at the party:

private int guests;

Create a constructor that prompts the user for the number of guests in the party,

stores the response in the guests field:

Add the following displayGuests method that displays the number of guests

provided by the user.

public void displayGuests()

{

// Displays total guests in the party

}

2. Creating a PartyDemo class:

Write a PartyDemo diver class that contains main() method. main() method

declares a Party object, supplies it with a value, and then displays the value. In other

word, simply create a party object and call displayGuests methods. Add the

following statement before creating Party object.

System.out.println("Creating a party");

At this point, you should get the output something similar to the following (Bold represent users input):

Creating a party

Enter the number of guests at your party: 15

Total Guests:15

3. Creating a Subclass:

Create a class DinnerParty. A DinnerParty is a type of Party at which

dinner is served, so DinnerParty is a child class of the Party.

A DinnerParty contains the number of guests, but you do not have to define the

variable here. The variable is already defined in the Party class, which is the

superclass of this class. You only need to add any variables that are particular

choice to a DinnerParty. Enter the following code to add an integer to hold the

dinner menu choices, which are 1 or 2 for beef or chicken, respectively:

private int dinnerChoice;

Add a method inputDinnerChoice(), which prompts the user for the choice

of entrees at the dinner party. 1 for beef and 2 for chicken. dinnerChoice variable

holds the value of user choice.

public void inputDinnerChoice()

{

// Your code here

}

Add another method displayDinnerChoice(), which displays Dinner

choice is beef if the user choose is 1 and displays Dinner choice is

chicken if user choose is 2.

public void inputDinnerChoice()

{

// your code here

}

4. Modify the PartyDemo class:

Add the following statement in the main method after the line that displayed the

party guest value (just before the closing brace of the program). When you run the

application, you understand that you are creating a DinnerParty.

System.out.println("Creating a party with dinner");

Now, create a DinerParty object and call the methods-inputDinnerChoice,

displayGuests, displayDinnerChoice using the DinerParty object.

At this point, you should get the output something similar to the following (Bold

represent users input) :

Creating a party

Enter the number of guests at your party: 15

Total Guests:15

Creating a party with dinner

Enter the number of guests at your party: 15

Enter dinner choice

1 for beef

2 for chicken

2

Total Guests:15

Dinner choice is chicken

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!