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; //constants, these values never change 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"); } System.out.println("Account Balance= " + f.format(balance)); System.out.println(); } 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; } } /** * main method */ // public static void main(String [] args) // { // account act = new account ("John Sloan", 1234, CHECKING, 6543.21); // //act.setBalance(357.20); // account act2 = new account(); // act.print(); // act2.print(); // // String sAccountName = act.getName(); // // int iNumber = act.getNumber(); // // double dBalance = act.getBalance(); // // int iType = act.getType(); // act2.setName("john"); // act2.setNumber(12); // act2.setBalance(500); // act2.setType(CHECKING); // // act.print(); // act2.print(); // } }