// Marty Stepp, CSE 142, Autumn 2009 // This is another example class. // 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. public class BankAccount { // private fields -- cannot be directly accessed outside this file private String name; private int id; private int pin; private String password; private double balance; // 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. public void deposit(double money) { if (0 <= money && money <= 500) { balance = balance + 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. public void withdraw(double money) { if (0 <= money && money <= balance) { balance = balance - money; } } // Returns the account user's current balance. public double getBalance() { return balance; } }