Simple representation of a bank account
@author
@version
import java.text.NumberFormat;
public class SimpleBankAccount{
private double balance;
private String accountId;
Constructor for objects of class SimpleBankAccount
public SimpleBankAccount(){
balance = 0.0;
accountId = "";
}
Constructor for objects of class SimpleBankAccount
public SimpleBankAccount( double bal, String id ){
balance = bal;
accountId = id;
}
Add money to the balance
@param amount
@return
public void deposit( double amount ){
balance += amount;
}
Remove money from the balance
@param amount
@return
public boolean withdraw( double amount ){
if( balance - amount >= 0 ){
balance -= amount;
return true;
}else{
return false;
}
}
Get the balance
@return
public double getBalance(){
return balance;
}
Set account ID
@param the
public void setAccountId(String id){
accountId = id;
}
Get the account ID
@return
public String getAccountId(){
return accountId;
}
Produces a string represenation of the balance
@return
public String toString( ){
String balanceStr = NumberFormat.getCurrencyInstance().format( balance );
return "Balance for account " + accountId + ": " + balanceStr + "\n";
}
}