Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A . A class called Beverage. This class is the base class ( or superclass ) for the other classes in the program. 1 .

A. A class called Beverage. This class is the base class (or superclass) for the other classes in the program.
1. The Beverage class must have the following private attributes:
String beverageName
int ounces
String addIns (cream, milk, sugar, lemon, etc..., separated by commas)
double price
2. The Beverage class needs to have a parameterized public constructor with parameters to provide values for the attributes listed above.
3. To provide appropriate access to the data in the attributes, the class must have public accessor ("getter") methods with appropriate return types to provide access to the data in the attributes:
String getBeverageName()
int getOunces()
String getAddIns()
double getPrice()
4. Override the toString() method inherited from the Object class to provide a reasonable String representation of the data in a Beverage object (beverage name, size in ounces, and price) in a format like
water (8 oz.) with lemon $0.49
Of course, the String returned by the toString() method should reflect the values in the Beverage object. Since there may or may not be any add-ins, the toString() method will need to use an appropriate selection statement to control that part of the output. The String representation of a Beverage object without any add-ins (addIns is an empty String) should look something like this:
water (8 oz.) $0.49
B. A subclass named Coffee that inherits from the Beverage base class.
1. The Coffee class should have the following private attributes:
String roastType
boolean decaf
2. The Coffee class needs a parameterized public constructor that calls the super() constructor with the appropriate arguments and then sets the values for the private attributes in the Coffee class.
The Coffee class "knows" that it is coffee, so the value "coffee" is passed as a literal String when the super() constructor is called. This means that the Coffee() constructor should have the following parameters:
o String roastType
o boolean decaf
o int ounces
o String addIns
o double price
3. The Coffee class needs to have public accessor methods for the attributes in the Coffee class.
String getRoastType()
boolean isDecaf()(Accessor methods for boolean values usual start with is... rather than get...
Remember that the public methods from the Beverage class are inherited by subclasses.
4. Override the inherited toString() method so that it produces an appropriate String representation of the data in a Coffee object. The String representation should be something like
decaf dark roast coffee (20 oz.) with cream $2.95
or
light roast coffee (16 oz.) $2.60
C. A subclass named Tea to the project that inherits from the Beverage base class.
1. Include at least 2 relevant private attributes (with appropriate data types) in the Tea class.
2. The Tea class needs to have a parameterized constructor that calls the super() base class constructor with the needed arguments and sets the values for the attributes in the Tea class.
3. The Tea class should have public accessor methods to provide appropriate access to the data in its private attributes.
4. The Tea class should have an appropriate override of the inherited toString() method that returns a String representing the data in a Tea object (similar to the toString() methods for the other classes but including the information relevant to tea).
D. Code the main() method in the application's driver class (DrinkOrderInheritance) so that it declares an array of 5 Beverage objects. To simplify this part of the program, the code in main() should use hard-coded values rather than relying on user input to do the following:
Populate the first element in the array with a plain Beverage object (such as the water shown above) by calling the Beverage() constructor.
Add 2 different Coffee objects by calling the Coffee() constructor to insert Coffee objects as the second and third array elements.
Add 2 different Tea objects to the array by calling the Tea() constructor.
Use an appropriate for loop to iterate over the array and print out the beverages. (Remember that System.out.println() will call the toString() method for the object passed in.)
E. Take a screen shot of the output from the program showing the list of beverages. Put the screen shot in a Word document. The output from the program should be similar to the foll

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

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

What does this public not want on this issue?

Answered: 1 week ago

Question

What does this public want on this issue?

Answered: 1 week ago