Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class CreditCard { // Instance variables: private String customer; // name of the customer (e.g., John Bowman) private String bank; // name of the

public class CreditCard { // Instance variables: private String customer; // name of the customer (e.g., "John Bowman") private String bank; // name of the bank (e.g., "California Savings") private String account; // account identifier (e.g., "5391 0375 9387 5309") private int limit; // credit limit (measured in dollars) protected double balance; // current balance (measured in dollars)

// Constructors: /** * Constructs a new credit card instance. * @param cust the name of the customer (e.g., "John Bowman") * @param bk the name of the bank (e.g., "California Savings") * @param acnt the account identifier (e.g., "5391 0375 9387 5309") * @param lim the credit limit (measured in dollars) * @param initialBal the initial balance (measured in dollars) */ public CreditCard(String cust, String bk, String acnt, int lim, double initialBal) { customer = cust; bank = bk; account = acnt; limit = lim; balance = initialBal; }

/** * Constructs a new credit card instance with default balance of zero. * @param cust the name of the customer (e.g., "John Bowman") * @param bk the name of the bank (e.g., "California Savings") * @param acnt the account identifier (e.g., "5391 0375 9387 5309") * @param lim the credit limit (measured in dollars) */ public CreditCard(String cust, String bk, String acnt, int lim) { this(cust, bk, acnt, lim, 0.0); // use a balance of zero as default }

// Accessor methods: /** Returns the name of the customer. */ public String getCustomer() { return customer; }

/** Returns the name of the bank */ public String getBank() { return bank; }

/** Return the account identifier. */ public String getAccount() { return account; }

/** Return the credit limit. */ public int getLimit() { return limit; }

/** Return the current balance. */ public double getBalance() { return balance; }

// Update methods: /** * Charges the given price to the card, assuming sufficient credit limit. * @param price the amount to be charged * @return true if charge was accepted; false if charge was denied */ public boolean charge(double price) { // make a charge if (price + balance > limit) // if charge would surpass limit return false; // refuse the charge // at this point, the charge is successful balance += price; // update the balance return true; // announce the good news }

/** * Processes customer payment that reduces balance. * @param amount the amount of payment made */ public void makePayment(double amount) { // make a payment balance -= amount; }

// Utility method to print a card's information 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); // implicit cast System.out.println("Limit = " + card.limit); // implicit cast } 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); // calling static method while (card.getBalance() > 200.0) { card.makePayment(200); System.out.println("New balance = " + card.getBalance()); } } } }

/* Output of main:

Customer = John Bowman Bank = California Savings Account = 5391 0375 9387 5309 Balance = 408.0 Limit = 5000 New balance = 208.0 New balance = 8.0 Customer = John Bowman Bank = California Federal Account = 3485 0399 3395 1954 Balance = 272.0 Limit = 3500 New balance = 72.0 Customer = John Bowman Bank = California Finance Account = 5391 0375 9387 5309 Balance = 436.0 Limit = 2500 New balance = 236.0 New balance = 36.0 */

Using the CreditCard class: a. Modify the CreditCard class to include a method that updates the credit limit; b. Modify the CreditCard class so that it ignores any request to process a negative payment amount.

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 Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions

Question

List the components of the strategic management process. page 72

Answered: 1 week ago