public class RewardCard extends CreditCard
CreditCard
except it offers reward points. In addition to the
dollar balance of an ordinary credit card, this card has a point
balance such that whenever a purchase is charged to the card, a certain
number of reward points is added to the point balance. Similarly if the
holder returned a purchase for refund, the point balance would be reduced by
the same rate. The accumulated points can be redeemed for free merchandise.Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_LIMIT
The default credit limit used by the two-argument constructor.
|
static int |
REWARD_RATE
The rate used to compute the number of reward points.
|
MIN_NAME_LENGTH, MOD, SEQUENCE_NUMBER_LENGTH
Constructor and Description |
---|
RewardCard(int no,
java.lang.String aName)
Construct a reward card having the passed number and holder name, and set
its initial dollar and point balances to zero.
|
RewardCard(int no,
java.lang.String aName,
double aLimit)
Construct a reward credit card having the passed number, holder name and
credit limit and set its initial dollar and point balances to zero.
|
Modifier and Type | Method and Description |
---|---|
boolean |
charge(double amount)
Attempt to charge this card.
|
void |
credit(double amount)
Credit the credit card (decrease its dollar balance) by the passed
amount.
|
int |
getPointBalance()
Return the number of reward points accumulated on this reward card.
|
boolean |
isSimilar(RewardCard other)
Test the similarity of two reward cards.
|
void |
redeem(int point)
Redeem the passed number of points and reduce the point balance
accordingly.
|
java.lang.String |
toString()
Return a string representation of this card.
|
equals, getBalance, getExpiryDate, getIssueDate, getLimit, getName, getNumber, hashCode, isSimilar, pay, setExpiryDate, setLimit
public static final double DEFAULT_LIMIT
public static final int REWARD_RATE
public RewardCard(int no, java.lang.String aName, double aLimit)
constructor
for
precondition details.no
- the credit card number, must be > 0 and ≤ 999999aName
- the name of the holder of this card, must have at least
CreditCard.MIN_NAME_LENGTH
charactersaLimit
- the credit limit, must be positivepublic RewardCard(int no, java.lang.String aName)
CreditCard.DEFAULT_LIMIT
for the credit limit.no
- the credit card number, must be > 0 and ≤ 999999aName
- the name of the holder of this card, must have at least
CreditCard.MIN_NAME_LENGTH
characterspublic int getPointBalance()
public boolean charge(double amount)
REWARD_RATE
.charge
in class CreditCard
amount
- the charge amounttrue
if successful and false
if such a
charge exceeds the available credit.public void credit(double amount)
REWARD_RATE
.credit
in class CreditCard
amount
- the amount to be credited.public void redeem(int point)
point
- the number of reward points to redeem.java.lang.RuntimeException
- if point
is negative or more than the point
balance.public java.lang.String toString()
toString
in class CreditCard
RWRD [NO=001005-3, BALANCE=7634.12, POINTS=500]
public boolean isSimilar(RewardCard other)
this
one if it has the same dollar
balance (to the nearest cent) and the same point balance as
this
one, regardless of card number. Even if the two cards
have different numbers, this method considers them similar as long as the
difference between their dollar balances is less than 0.01 and the
difference between their point balances is zero.other
- a reference to the credit card object to test equality with.true
if other
is not null and it points
to an object that is similar (as defined above) to is similar (as
defined above) to this
object, and
false
otherwise.