Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the PredatoryCreditCard class so that a customer is assigned a minimum monthly payment, as a percentage of the balance, and so that a late

Modify the PredatoryCreditCard class so that a customer is assigned a minimum monthly payment, as a percentage of the balance, and so that a late fee is assessed if the customer does not subsequently pay that minimum amount before the next monthly cycle.

public class CreditCard {

private String customer;

private String bank;

private String account;

private int limit;

protected double balance;

public CreditCard(String cust, String bk, String acnt, int lim, double initialBal) {

customer = cust;

bank = bk;

account = acnt;

limit = lim;

balance = initialBal;

}

public CreditCard(String cust, String bk, String acnt, int lim) {

this(cust, bk, acnt, lim, 0.0);

}

protected void setBalance(double newBalance) {

this.balance = newBalance;

}

public String getCustomer() {

return customer;

}

public String getBank() {

return bank;

}

public String getAccount() {

return account;

}

public int getLimit() {

return limit;

}

public double getBalance() {

return balance;

}

public boolean charge(double price) {

if(price + balance > limit)

return false;

balance += price;

return true;

}

public void makePayment(double amount) {

balance -= amount;

}

public static void printSummary(CreditCard card) {

System.out.println("Customer" + card.customer);

System.out.println("Bank" + card.bank);

System.out.println("Account" + card.account);

System.out.println("Balance" + card.balance);

System.out.println("Limit" + card.limit);

}

public static void main(String[] args) {

CreditCard[] wallet = new CreditCard[3];

wallet[0] = new CreditCard("John Bowman", "California Savings", "5391 0375 9387 5309", 5000);

wallet[1] = new CreditCard("John Bowman", "California Federal", "3485 0399 3395 1954", 3500);

wallet[2] = new CreditCard("John Bowman", "California Finance", "5391 0375 9387 5309", 2500, 300);

for(int val = 1; val <= 16; val++) {

wallet[0].charge(3*val);

wallet[1].charge(2*val);

wallet[2].charge(val);

}

for(CreditCard card : wallet) {

CreditCard.printSummary(card);

while (card.getBalance() > 200.0) {

card.makePayment(200);

System.out.println("New balance = " + card.getBalance());

}

}

}

}

class PredatoryCreditCard extends CreditCard {

private double apr;

private int count = 0;

public PredatoryCreditCard(String cust, String bk, String acnt, int lim,

double initialBal, double rate) {

super(cust, bk, acnt, lim, initialBal);

apr = rate;

}

public void processMonth() {

if (getBalance() > 0) {

double monthlyFactor = Math.pow(1 + apr, 1.0/12);

balance *= monthlyFactor;

}

count = 0;

}

public boolean charge(double price) {

boolean isSuccess = super.charge(price);

count++;

if(!isSuccess) {

balance += 5;

}

if (count > 10) {

balance += 1;

}

return isSuccess;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions