JAVA
Write the abstract super classTransaction, and two of its subclasses,Payment andSale
(you do not need to supply any comments other than your name).
I. Write an abstract superclass encapsulating a Transaction:
The Transaction super class has an instance variable representing the customers name, and 3 methods:
- an overloaded constructor,
- a toString() method that returns a message including the name of the customer,
- and an abstract method called calculateAmount()which will be implemented in your subclasses.
II. Write a non-abstract subclass that inherits from the Transaction class encapsulating a Payment:
The Payment class has instance variable representing the payment amount received and 3 methods.
- It has an overloaded constructor,
- a toString() method that returns a message including customers name, the name of the class Payment, and the payment amount,
- an non-abstract class called calculateAmount() which returns the payment amount.
III. Write a second non-abstract subclass that inherits from the Transaction class encapsulating a Sale:
The Sale class has 2 instance variables representing the price and quantity of the sale and 3 methods.
- It has an overloaded constructor,
- a toString() method that returns a message including the customers name, the name of the class Sale, plus the price and quantity of the sale.
- calculateAmount() which returns the total amount of the sale (quantity times price, with an eight and a-half percent sales tax).
IV. Write a client program which instantiates 3 objects of your subclasses and stores them in an array ofTransactionobjects or anArrayList ofTransaction objects. Your client program should process your array orArrayListcalling the toString()followed by the calculateAmount( ) methods which will print the contents of the array.
Sample Program Output:
Bob Jones Sale 19.95 1
Total Amount: $ 21.65
Jane Doe Payment 150.87
Total Amount: $ 150.87
Jack Torance Sale 50.00 2
Total Amount: $ 108.50