// A class with data for a savings account. // This first example illustrates how to define a class with non-public // instance variables and some public methods. // // API of this class: // // public class Account // { // public Account (String n, double b) // public String getname() // public double getbalance() // public void withdraw (double amount) // public void deposit (double amount) // public double monthactivity () // } public class Account { // instance variables String name; double balance; static double interestrate = .04; // constructor method is used to initialize instance variables public Account (String n, double b) { name = n; balance = b; } // accessor methods public String getname() { return name; } public double getbalance() { return balance; } // other methods public void withdraw (double amount) { if ((balance - amount) > 0) { balance -= amount; } else { } // later will return exception "insufficient funds" } public void deposit (double amount) { balance += amount; } // returns monthly interest and updates balance public double monthactivity() { double interest = (balance * interestrate)/12; balance += interest; return interest; } }