Carly's Catering provides meals for parties and special events. In Chapter 3, you created an Event class for the company. The Event class contains two public final static fields that hold the price per guest ($35) and the cutoff value for a large event (50 guests), and three private fields that hold an event number, number of guests for the event, and the price. It also contains two public set methods and three public get methods. Now, modify the Event class to contain two overloaded constructors. One constructor accepts an event number and number of guests as parameters. Pass these values to the setEventNumber() and setGuests() methods, respectively. The setGuests() method will automatically calculate the event price. The other constructor is a default constructor that passes "A000" and 0 to the two-parameter constructor. Save the file as Event.java. b. In Chapter 3, you also created an EventDemo class to demonstrate using two Event objects. Now, modify that class to instantiate two Event objects, and include the following new methods in the class: Instantiate one object to retain the constructor default values. Accept user data for the event number and guests fields, and use this data set to instantiate the second object. Display all the details for both objects. Save the file as EventDemo.java. Create a zip file of the .java file(s) and submit the a
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Carly's Catering provides meals for parties and special events. In Chapter 3, you created an Event class for the company. The Event class contains two public final static fields that hold the price per guest ($35) and the cutoff value for a large event (50 guests), and three private fields that hold an event number, number of guests for the event, and the price. It also contains two public set methods and three public get methods.
Now, modify the Event class to contain two overloaded constructors.
- One constructor accepts an event number and number of guests as parameters. Pass these values to the setEventNumber() and setGuests() methods, respectively. The setGuests() method will automatically calculate the event price.
- The other constructor is a default constructor that passes "A000" and 0 to the two-parameter constructor.
Save the file as Event.java.
b. In Chapter 3, you also created an EventDemo class to demonstrate using two Event objects. Now, modify that class to instantiate two Event objects, and include the following new methods in the class:
- Instantiate one object to retain the constructor default values.
- Accept user data for the event number and guests fields, and use this data set to instantiate the second object. Display all the details for both objects.
Save the file as EventDemo.java.
Create a zip file of the .java file(s) and submit the assignment.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps