Write the abstract super class Transaction, and two of its subclasses, Payment and Sale (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 of Transaction objects or an ArrayList of Transaction objects. Your client program should process your array or ArrayList calling the toString()followed by the calculateAmount( ) methods which will print the contents of the array.
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:
Write the abstract super class Transaction, and two of its subclasses, Payment and Sale (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 of Transaction objects or an ArrayList of Transaction objects. Your client program should process your array or ArrayList calling the toString()followed by the calculateAmount( ) methods which will print the contents of the array.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 1 images