CreditCardAccount Write a class to represent a credit card C
CreditCardAccount: Write a class to represent a credit card. Call it CreditCardAccount. 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. Use 9%.
lastAccountNumber – The last account number assigned to a customer. Account numbers should be assigned sequentially. Start with 5555.
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
$1000
300-500
baseRate + 7%
$3000
500-700
baseRate + 3%
$7000
700+
baseRate
$15000
makePurchase – Takes a purchase amount as a parameter and updates the current balance. If the amount + balance > creditLimit, deny the transaction (print a message to that effect, don\'t change the balance).
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.
applyInterest – 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.
| Credit Score | Rate | Limit |
| 0-300 | baseRate + 12% | $1000 |
| 300-500 | baseRate + 7% | $3000 |
| 500-700 | baseRate + 3% | $7000 |
| 700+ | baseRate | $15000 |
Solution
package chegg;
public class CreditCardAccount {
static int baseRate=9;
int lastAccountNumber=555;
public int getLastAccountNumber() {
return lastAccountNumber;
}
public void setLastAccountNumber(int lastAccountNumber) {
this.lastAccountNumber = lastAccountNumber;
}
public String getAccountholder() {
return accountholder;
}
public void setAccountholder(String accountholder) {
this.accountholder = accountholder;
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
public float getCreditScore() {
return creditScore;
}
public void setCreditScore(float creditScore) {
this.creditScore = creditScore;
}
public float getRate() {
return rate;
}
public void setRate(float rate) {
this.rate = rate;
}
public float getBalance() {
return balance;
}
public void setBalance(float balance) {
this.balance = balance;
}
public float getCreditLimit() {
return creditLimit;
}
public void setCreditLimit(float creditLimit) {
this.creditLimit = creditLimit;
}
String accountholder;
int accountNumber;
float creditScore;
float rate;
float balance;
float creditLimit;
int checkAvail()
{
lastAccountNumber=lastAccountNumber+1;
accountNumber=lastAccountNumber;
return accountNumber;
}
Date212(String accountholder,float creditScore)
{
int sts= checkAvail();
if(creditScore>0 && creditScore<300)
{
baseRate=baseRate+12;
setRate(baseRate);
creditLimit=1000;
setCreditLimit(creditLimit);
}
if(creditScore>300 && creditScore<500)
{
baseRate=baseRate+7;
creditLimit=3000;
setRate(baseRate);
setCreditLimit(creditLimit);
}
if(creditScore>500 && creditScore<700)
{
baseRate=baseRate+3;
creditLimit=7000;
setRate(baseRate);
setCreditLimit(creditLimit);
}
if(creditScore>700)
{
baseRate=baseRate+0;
creditLimit=15000;
setRate(baseRate);
setCreditLimit(creditLimit);
}
}
int makePurchase(float amount){
float bal;
if(getCreditLimit()>=amount+getBalance()){
bal= (getCreditLimit()-amount);
setBalance(bal);
}
else
System.out.println(\"Low Balance\");
return 0;
}
int makePayment(float amount){
float cl;
cl= (getCreditLimit()+amount);
if(getBalance()<amount){
setBalance(0);
}
if(amount<(0.01*getBalance()))
{
setRate(getRate()+1);
//setCreditLimit(cl);
}
if(amount==getBalance())
{
setCreditScore(getCreditScore()+10);
//setCreditLimit(cl);
}
{setBalance(getBalance()-amount);}
setCreditLimit(cl);
return 0;
}
int raiseRate(float r)
{
setRate(getRate()+r);
return 0;
}
int raiseLimit(float r)
{
setCreditLimit(getCreditLimit()+r);
return 0;
}
float applyInterest ()
{
float balance;
balance=getBalance() + (getBalance() * (getRate() / 12));
return balance;
}
public String toString(){
System.out.println(\"Account Holder Name \"+\"--------\"+getAccountholder());
System.out.println(\"Account numb\"+\"--------\"+\"*****\"+getLastAccountNumber());
System.out.println(\"Balance\"+\"----\"+getBalance());
System.out.println(\"Limit\"+\"----\"+getCreditLimit());
return \"\";
}
}



