Working with credit cards
/home/cs230/download/Lab03CreditCardDriver executable program to get
familiar with the way the program works. What is a driver?
Here are the implementation details:
baseRate - The minimum interest rate that the card can have. This should be a constant
that is hard coded.lastAccountNumber - The last account number assigned to a customer. Account numbers should be
assigned sequentially. So, the first customer gets assigned the number 1,
the second customer the number 2, etc. accountholder - The name of the person who owns the card.accountNumber - A unique 7-digit identifier number.creditScore - The account holder's credit score.rate - The annual interest rate charged to the card.balance - The current balance on the card.creditLimit - The card holder's credit limit.Constructor() - Should only take the account holder's name and a credit score. The next account
number available should be assigned. The balance will be 0 as nothing has
been charged yet. The rate and credit limit will be determined by the
credit score. Use the following table to set the rate and credit limit.
|
Credit Score |
Rate |
Limit |
|
0-300 |
baseRate + 10% |
$1000 |
|
300-500 |
baseRate + 7% |
$3000 |
|
500-700 |
baseRate + 4% |
$7000 |
| 700+ |
baseRate + 1% |
$15000 |
getBalance() - Returns the current balance. This simple method is what we call a getter method: it gets the value of an instance variable.
makePurchase() - Takes a purchase amount as a parameter and updates the current balance.
If the amount + balance creditLimit, deny the transaction.makePayment() - Takes
a payment amount as a parameter and updates the current balance. If the
payment is greater than the balance, set the balance to zero and print an
appropriate message. If the payment is less than 10% of the balance,
apply the payment and raise the account holder's rate by 1%. If the
balance is paid off entirely, raise the creditScore by 10. If the
increased creditScore changes where the account holder falls in the above
table, change the rate and limit as appropriate.raiseRate() - Raises the account holder's rate by a given percentage.raiseLimit() - Raises the account holder's limit by a given dollar amount.calculateBalance() - Calculates the balance on a monthly basis. Remember that the rate is
yearly, so the formula for calculating the balance monthly is balance +
(balance * (rate / 12)).toString() - Print the account holder's name, account number obscured with stars (ex: 1234567
would display as ****567), balance, and limit.CreditCard classmain() method of your program. Create a CreditCard object,
and call the methods on it as you define them. You should be reasonably confident, at this point, that your
methods are working as intended.
To thoroughly test your class, run the driver program, in the provided file
CreditCardDriver.java. This program tracks an account
holder over a three month period:
if-statements, others relatively new, like the
do-while loop. Note that CreditCardDriver.java
uses the Scanner class to read input in from the keyboard.
Here is a short example using the Scanner class.
CreditCardsArray.
An instance of the CreditCardsArray class will store a collection of
CreditCard instances.
CreditCards
(is there any other type of container that could be used in this case, instead of an array?)
CreditCardsArray.java class
toString() method,
to return a string representation of all the contents of a CreditCardsArray instance.
This method will be helpful with the incremental testing of your code.
The implementation of toString() will be very simple, if you take advantage of the
toString() method in the CreditCard class.
Then, as time permits:
CreditCard objects (for example, define a method to search the collection for a certain holder's name)
CreditCard class (e.g. getBalance() might come in handy)