// Helene Martin, CSE 142 // Models a bank account // Each BankAccount object represents an account including its balance, owner // and number. Transactions such as deposits or withdrawals can be performed. public class BankAccount { private int accountNum; private String username; private double balance; private int transactions; // number of transactions completed // list of transactions // interestRate // password // checking or savings // creates an account with the given number, user name and balance public BankAccount(int num, String name, double initialBalance) { System.out.println("Creating account for " + name); accountNum = num; username = name; balance = initialBalance; } // returns account number public int getAccountNum() { return accountNum; } // returns user name public String getUsername() { return username; } // returns balance public double getBalance() { return balance; } // deposits amount if it is greater than 0 public void deposit(double amount) { if (amount > 0) { balance += amount; transactions++; } } // withdraws amount, returns true for success (enough funds) // false otherwise public boolean withdraw(double amount) { if (balance - amount >= 0 && amount > 0) { balance -= amount; transactions++; return true; } return false; } // returns a String representation of this account public String toString() { return "#" + accountNum + " (" + username + "): $" + balance; } }