Question: package dsaj.primer; Chapter 1 content This is Credit card.java /** * A simple model for a consumer credit card. * * @author Michael T. Goodrich

package dsaj.primer; Chapter 1 content This is Credit card.java /** * A simple model for a consumer credit card. * * @author Michael T. Goodrich * @author Roberto Tamassia * @author Michael H. Goldwasser */ 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 200.0) { card.makePayment(200); System.out.println("New balance = " + card.getBalance()); } } } } Refer to the Credit Card.java from Ch1 Code. Suppose the main method looks like public static void main(String[] args) { Creditcard[] wallet = new CreditCard[2]; wallet[@] = new CreditCard("Herky Hawk", "Hills Bank", "1234 9999 0000 2222", 1100); wallet[1] = new Creditcard("Herky Hawk", "UI Credit Union", "9999 8888 1111 0000", 1700); for (int val = 1; val 500.0) { card.makePayment(100); System.out.println("New balance = + card.getBalance()); } } What does the program print? To answer, complete the below: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
