Question
In java, without importing Comparator A bank offers two kinds of credit cards, silver and golden cards. With silver cards, customers pay a fee, e.g.
In java, without importing Comparator
A bank offers two kinds of credit cards, silver and golden cards. With silver cards, customers pay a fee, e.g. 15%, for all card transactions. With golden cards, they pay a fixed monthly fee, e.g. 100. Design the class Card that has two instance variables card no (int) and transactions (ArrayList of doubles). It has only one constructor, with one argument, card no, that creates a card object. Include getters/ setters for all variables. Override the toString method to return card no and the total amount, including the fees, that must be paid by the card owner. Include the method purchase(double amount) that adds a new transaction to the transactions lists. Override the equals method. Two cards are equal if they have the same card no. The class implements Comparable, the comparison is based on the total amount, including the fees, that must be paid by the card owner. The subclass SilverCard has one instance variable transactionFee (double). Include one constructor with all the arguments. Do not include getters/ setters. Override the toString method to return the fee, card no, and the total amount. Override the purchase method to compute the fee and append it as a new transaction to the transaction lists. The subclass GoldenCard has one instance variable monthlyFee (int). Include one constructor with all the arguments. Do not include getters/ setters. Override the toString method to return the monthly fee, card no, and the total amount. Do not override the purshace method. Design a test class that creates an array of type Card. Fill the array with objects from various subclasses. Do some transactions with all cards, call the method purchase with random amounts. Sort the array using Arrays.sort method based on the total amount then print it. Finally find the total amount of all GoldenCard objects in the array. Notes: - All variables are private - You may add methods, other than mentioned above, to the classes if needed
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