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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!