// CSE 142, Autumn 2010, Marty Stepp // This class defines a new type of objects called BankAccount. // Each BankAccount object represents one user's account at a bank, // including the account balance, personal info, and so on. // BankAccount objects include behavior for making transactions on the account // such as deposits and withdrawals. public class BankAccount { // fields - the variables in each object int number; double balance; int ssn; String name; int pin; String address; // Deposits the given amount from this bank account. // If the amount is negative, the transaction is aborted. public void deposit(double amount) { if (amount > 0.0) { balance = balance + amount; } } // Withdraws the given amount from this bank account. // If the amount is negative or the account does not have that much money, // the transaction is aborted. public void withdraw(double amount) { if (amount > 0.0 && amount <= balance) { balance = balance - amount; } } // Returns a String representation of this bank account object, // so that it can be printed. // Example: "Marty: $5.25" public String toString() { return name + ": $" + balance; } }