Answered step by step
Verified Expert Solution
Question
1 Approved Answer
After the project opens, expand the Project Tree for the project. Right click on the package node for the project and select New - -
After the project opens, expand the Project Tree for the project. Right click on the package node for the project and select New Java Class... to add the following to the project:
A An abstract class called Beverage. This abstract class is the base class for the other classes in the program. The parameterized constructor should be protected rather than public since it should only be accessible from subclasses. The accessor methods and toString method should be the same as the Beverage class from the first assignment.
B Add the Coffee and Tea classes that extend the abstract Beverage base class.
C Declare an interface named PaymentMethod by right clicking on the package for the package and selecting New and then Java Interface... The interface should include a public method named processPayment that takes a double as its parameter and returns a boolean. The parameter represents the amount of the payment, and the boolean represents whether the payment was successful or not
D Declare a CreditCard class that implements the PaymentMethod interface. This class should have a String attribute for the credit card number and a parameterized constructor that sets the value of the credit card number. The overridden processPayment method should print out a message that the payment was successful and return true since there isn't really a way to process the payment
E Declare a Cash class that implements the PaymentMethod interface. This class should have a double attribute for the amount tendered and a parameterized constructor that sets the value of this attribute. The overridden processPayment method should print out the amount tendered, print the change due, and then return true.
F Study the Order class and note how it makes use of the classes that inherit from the abstract Beverage class and those that implement the PaymentMethod interface. In the main method in the DrinkOrderAbstract class, construct Order objects. Use the Order class's add method to add up to Coffee or Tea objects to each order. Use the Order class's setPayment method to add a credit card payment to one order and a cash payment to the other. For each order, print out the list of drinks in the order, the total price for the order, and the payment. The exact output will vary, but the result should look something like this:
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