Question: 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: A protected instance variable amount of type double that stores the amount of the payment A parameterized constructor to initialize the instance variable Appropriate setter and getter methods for the amount variable 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: 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 digit arranged in groups and must be in the format NNNN NNNN NNNN NNNN A parameterized constructor to initialize the instance variables Override the toString method to display all details of the CreditCardPayment 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 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 classC Implement a test class main method only that performs the following: Create two objects of type CreditCardPayment with appropriate initial values of your choice Call the toString method for both objects 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" 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
