// CSE 143, Autumn 2013 // Each BankAccount object represents account information for a bank customer. // We use private fields and public methods to make sure that the user // cannot ever have a negative account balance. // import java.util.*; public class BankAccount { private int id; private double balance; private ArrayList transactions; // Constructs a new account with the given ID and a balance of $0.00. public BankAccount(int id) { this.id = id; balance = 0.0; transactions = new ArrayList(); } // Deposits the given amount of money into the user's account. // If the deposit amount is too big (more than $500), or if it is // negative, the method does nothing. // Also records a log entry of the deposit to be printed later. public void deposit(double money) { if (0 <= money) { balance = balance + money; transactions.add("deposit $" + money); } } // Withdraws the given amount of money from the user's account. // If the user does not have enough money, or if the amount of money // is negative, the method does nothing. // Also records a log entry of the withdrawal to be printed later. public void withdraw(double money) { if (0 <= money && money <= balance) { balance = balance - money; transactions.add("withdraw $" + money); } } // Returns the account user's current balance. public double getBalance() { return balance; } // Returns the account user's ID number. public double getID() { return id; } // Prints a log of all transactions (deposits and withdrawals) that have // been made on this account, one per line. public void printLog() { for(int i = 0; i < transactions.size(); i++) { System.out.println(transactions.get(i)); } } }