Question
Define a class named Payment that contains an instance variable paymentAmount (non-static member variable) of type double that stores the amount of the payment and
Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method with contents of payment amount and details.
Next, define a class named CashPayment that is derived from Payment. This class have an additional instance variable of type String (a non-static member variable) that specifies a type of currency, such as "dollar", "euro", "peso", "yen", etc. This class should redefine the paymentDetails method to indicate that the payment is in cash, and type of currency. Include appropriate constructor(s). Override toString() method with contents of payment details.
Define a class named CreditCardPayment that is derived from Payment. This class should contain instance variables (member variables) for the name on the card, expiration date, and credit card number. Include appropriate constructor(s). Finally, redefine thepaymentDetails method to include all credit card information in the printout.
Override toString() method with contents of cash payment details.
Create a PayTester class with main method that creates at least two CashPayment and two CreditCardPayment objects with different values. Set payment for two objects by using setPaymentAmount() (mutator) method. Call toString() methods from each object to get the details of payments.
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