Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java, Design and implement a class hierarchy to model different types of payments. Create a superclass named Payment that encapsulates common attributes and behaviors

Using Java, Design and implement a class hierarchy to model different types of payments. Create a superclass named Payment that encapsulates common attributes and behaviors of all types of payments. Additionally, create a subclass named CreditCardPayment to represent a payment made by a credit card.A. The superclass Payment should include the following:1. A protected instance variable amount of type double that stores the amount of the payment.2. A parameterized constructor to initialize the instance variable.3. Appropriate setter and getter methods for the amount variable.4. An instance method named toString that returns sentence to describe the amount of the payment.B. The subclass CreditCardPayment should inherit the instance variable and methods of the Payment class. It should include the following:1. Private instance variables for the payment made by a credit card; name, of type String, Expiration date of type Date and a credit card number of type String. (The credit card number is made of 16 digit arranged in 4 groups and must be in the format "NNNN NNNN NNNN NNNN".2. A parameterized constructor to initialize the instance variables.3. Override the toString method to display all details of the CreditCardPayment.4. Override the equals method to compare two CreditCardPayment based on their number and amount. The method should return true if the payments number and amount are the same, and false otherwise.5. Implement isValidCard method that return true if the current date is before the expiration date of the card, and false otherwise.(Hint: search and use appropriate method from java.lang.Date class).C. Implement a test class (main method only) that performs the following:1. Create two objects of type CreditCardPayment with appropriate initial values of your choice.2. Call the toString method for both objects.3. Check if the first object is equal to the second object. If the first object is equal to the second object, print "Equal"; otherwise, print "Not Equal".4. Use the isValidCard to print is still valid or expired card messages for both objects.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions