import javax.swing.JOptionPane; public class BankAccount { /* we want to be able to: * - deposit money * - withdraw money * - get the balance */ // INSTANCE VARIABLE: private double balance; // CONSTRUCTOR: // initializes any instance variables you want to initialize // it has the same name as the class public BankAccount() { balance = 0; } // public - other methods can call this method // void - the method has no return statement // amount - parameter public void deposit(double amount) { balance = balance + amount; // shorthand: balance += amount; } public void withdraw(double amount) { balance = balance - amount; // shorthand: balance -= amount; } // the "double" indicates that the method returns a double public double getBalance() { return balance; } public static void main(String[] args) { BankAccount harrysChecking = new BankAccount(); harrysChecking.deposit(2240.59); harrysChecking.withdraw(500); // this line has an example of storing a result returned by a method: double currentBalance = harrysChecking.getBalance(); String msg = "Current balance: " + currentBalance; JOptionPane.showMessageDialog(null, msg); } }