import java.text.DecimalFormat; /** * base class account * * John Sloan * January 24, 2009 */ public class account { protected String name; protected int number; protected double balance; protected int type; protected DecimalFormat f; public static final int CHECKING = 0; public static final int SAVINGS = 1; /** * Default Constructor */ public account() { initFormatting(); name = "no name for this account"; type = CHECKING; balance = 0.0; } /** * Secondary constructor this time with parameters * that setup the account information. */ public account(String fullName, int accountNumber, int accountType, double accountBalance ) { initFormatting(); name = fullName; number = accountNumber; type = accountType; balance = accountBalance; if( accountType == CHECKING){ type = CHECKING; } else{ type = SAVINGS; } } public void initFormatting() { f = new DecimalFormat(); f.applyPattern( "$#,##0.00;-$#,##0.00"); } /** * method prints account summary. */ public void print() { System.out.println("Account Name= " + name); System.out.println("Account Number= " + number); if( type == CHECKING){ System.out.println("Account Type= Checking"); } if( type == SAVINGS){ System.out.println("Account Type= Savings"); } initFormatting(); System.out.println("Account Balance= " + f.format(balance)); } public void deposit(double depositAmount) { if(depositAmount > 0){ balance = balance + depositAmount; } else{ System.out.print("Error: deposit amount must be positive"); } } public void withdrawl(double withdrawlAmount) { if(withdrawlAmount > 0){ balance = balance - withdrawlAmount; } else{ System.out.println("Error: withdrawl amount must be positive"); } } /** * accessor methods. */ public String getName() { return name; } public int getNumber() { return number; } public double getBalance() { return balance; } public int getType() { return type; } /** * mutator methods. */ public void setName(String change) { name = change; } public void setNumber( int card) { number = card; } public void setBalance( double newBalance) { if(newBalance < 0){ balance = 0; } else{ balance = newBalance; } } public void setType(int newType) { if ( (newType != CHECKING) || (newType != SAVINGS) ){ type = CHECKING; } else{ type = newType; } } }