/** * Demonstration class for CSE 142 lecture on testing and debugging. * 2/03 */ public class CreditCard { // instance variables public String name; // account name public int number; // account number public double limit; // account limit, must be >= 0.00 public double balance; // account balance, must have // 0.0 <= balance <= limit /** * Charge amount to this CreditCard if amount+balance <= limit. * If successful, return true; if not, change nothing and return false */ public boolean charge(double amount) { // System.out.println("charge method entered"); if (amount + balance <= limit) { // System.out.println("In amount + balance <= limit condition in charge method"); balance = balance + amount; return true; } else { return false; } } /** * Return the current balance of this CreditCard */ public double getBalance() { // System.out.println("getBalance entered; balance = " + balance); return balance; } /** * return a String representation of this CreditCard */ public String toString() { String result = "CreditCard[name = " + name + ", number = " + number + ", limit = " + limit + ", balance = " + balance + "]"; return result; } /** * Construct new CreditCard with given name, number, and limit, and * with a balance of 0.0 */ public CreditCard(String name, int number, double limit) { // System.out.println("CreditCard constructor entered"); this.name = name; this.number = number; this.limit = limit; this.balance = 0.0; } }