Question
Please do it in java. The PrepaidCard class extends BankCard. It defines the instance methods below (it does not add any new instance variables). Note
Please do it in java.
The PrepaidCard class extends BankCard. It defines the instance methods below (it does not add any new instance variables). Note that several of these operations are somewhat different from their counterparts in CreditCard and RewardsCard!
a. public PrepaidCard(String cardHolder, long cardNumber, double balance). For now, you may assume that the card number is always valid.
b. public PrepaidCard(String cardHolder, long cardNumber). This constructor sets the starting balance to 0. For now, you may assume that the card number is always valid.
c. public boolean addTransaction(Transaction t). This method works as follows:
i. If the Transaction type is "debit" and the transaction amount is less than or equal to this card's balance, the transaction is accepted; subtract its amount from the card balance, add the Transaction to the ArrayList of transactions, and return true.
1 Note that this may bring the card balance below 0. This is acceptable for the basic assignment; one of the extra-credit options asks you to fix this.
If the Transaction type is "debit" and its amount is greater than the card balance, the transaction has been declined. Do not change the card balance or the ArrayList; just return false.
IftheTransactiontypeis"credit",subtractitsamountfromthecardbalance(creditshave negative amounts, so this effectively adds money back to the PrepaidCard), add the Transaction to the ArrayList of transactions, and return true.
IftheTransactionhasanyothertype(like"redemption"),donotchangethecardbalance or the ArrayList; just return false.
public boolean addFunds(double amount). This method works as follows:
If the parameter is positive, it is added to the card's balance, and a new Transaction is added to the PrepaidCard's ArrayList with a type of "top-up", a merchant name of "User payment", an amount equal to the argument, and no notes. Return true to indicate success.
Otherwise, do not modify the balance or the transaction list. Return false to indicate failure.
public String toString(). This method returns a String that contains, at minimum, the
card number and its current balance.
publicvoidprintStatement().Thismethodimplementstheabstractmethodfrom BankCard. It prints out a neatly-formatted list of card transactions, along with the rest of the card's information (cardholder name, card number, and ending balance).
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