Package com.zybooks.dsaj.primer
Class CreditCard
java.lang.Object
com.zybooks.dsaj.primer.CreditCard
- Direct Known Subclasses:
PredatoryCreditCard
A simple model for a consumer credit card.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreditCard
(String cust, String bk, String acnt, int lim) Constructs a new credit card instance with default balance of zero.CreditCard
(String cust, String bk, String acnt, int lim, double initialBal) Constructs a new credit card instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
charge
(double price) Charges the given price to the card, assuming sufficient credit limit.Return the account identifier.double
Return the current balance.getBank()
Returns the name of the bankReturns the name of the customer.int
getLimit()
Return the credit limit.static void
void
makePayment
(double amount) Processes customer payment that reduces balance.static void
printSummary
(CreditCard card)
-
Field Details
-
balance
protected double balance
-
-
Constructor Details
-
CreditCard
Constructs a new credit card instance.- Parameters:
cust
- the name of the customer (e.g., "John Bowman")bk
- the name of the bank (e.g., "California Savings")acnt
- the account identifier (e.g., "5391 0375 9387 5309")lim
- the credit limit (measured in dollars)initialBal
- the initial balance (measured in dollars)
-
CreditCard
Constructs a new credit card instance with default balance of zero.- Parameters:
cust
- the name of the customer (e.g., "John Bowman")bk
- the name of the bank (e.g., "California Savings")acnt
- the account identifier (e.g., "5391 0375 9387 5309")lim
- the credit limit (measured in dollars)
-
-
Method Details
-
getCustomer
Returns the name of the customer. -
getBank
Returns the name of the bank -
getAccount
Return the account identifier. -
getLimit
public int getLimit()Return the credit limit. -
getBalance
public double getBalance()Return the current balance. -
charge
public boolean charge(double price) Charges the given price to the card, assuming sufficient credit limit.- Parameters:
price
- the amount to be charged- Returns:
- true if charge was accepted; false if charge was denied
-
makePayment
public void makePayment(double amount) Processes customer payment that reduces balance.- Parameters:
amount
- the amount of payment made
-
printSummary
-
main
-