Java Foundations Chapter 5 Assignment (10 marks, 4% for the final grade)
Name: (print) ______/ Grade: ______Credit Cards (10 marks)
In this exercise, you will write a class to represent a credit card. The class details are as follows:
- Static Variables
- baseRate – The minimum interest rate that the card can have. This should be a constant that is hard coded. For this assignment, set the baseRate to be a constant equals 5.3 percent.
- lastAccountNumber – The last account number assigned to a customer. Account numbers should be assigned sequentially.
- Instance Variables
- 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.
- Methods
- 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
- 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.
To test your class, write a driver program to track an account holder over six months. Each month, allow the account holder to make as many purchases as he wishes. At the end of each month, if the balance is greater than 0, ask the user if he would like to make a payment. Apply the payment if he makes one. If a payment is not made during any given month when there is a balance on the card, raise the rate by 2%. Finally, calculate the new balance at the end of each month.
Page 1 of 1