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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 16RQ
icon
Related questions
Question

JAVA

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.

 

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT