// 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. // Nancy McCracken 3/14/97 public class Account { // instance variables String name; float balance; static float interestrate = .04F; // constructor method is used to initialize instance variables public Account (String n, float b) { name = n; balance = b; } // accessor methods public String getname() { return name; } public float getbalance() { return balance; } public int getbalancedollars() { return (int)Math.floor(balance); } public int getbalancecents() { return (int)(balance - Math.floor(balance))*100 ; } // other methods public String withdraw (float amount) { if ((balance - amount) > 0) { balance -= amount; return "ok"; } else return "insufficient funds"; } public void deposit (float amount) { balance += amount; } public void monthactivity() { balance = balance + (balance * interestrate)/12; } }