Answered step by step
Verified Expert Solution
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.
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
The Beverage class needs to have a parameterized public constructor with parameters to provide values for the attributes listed above.
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
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 oz with lemon $
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 addins, 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 addins addIns is an empty String should look something like this:
water oz $
B A subclass named Coffee that inherits from the Beverage base class.
The Coffee class should have the following private attributes:
String roastType
boolean decaf
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
The Coffee class needs to have public accessor methods for the attributes in the Coffee class.
String getRoastType
boolean isDecafAccessor methods for boolean values usual start with is rather than get...
Remember that the public methods from the Beverage class are inherited by subclasses.
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 oz with cream $
or
light roast coffee oz $
C A subclass named Tea to the project that inherits from the Beverage base class.
Include at least relevant private attributes with appropriate data types in the Tea class.
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.
The Tea class should have public accessor methods to provide appropriate access to the data in its private attributes.
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 Beverage objects. To simplify this part of the program, the code in main should use hardcoded 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 different Coffee objects by calling the Coffee constructor to insert Coffee objects as the second and third array elements.
Add 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started