import java.io.*; public class BankAcc { public static int numAccsMade = 0; BufferedReader comingIn; private double balance; private String password, name; private boolean overdraftAllowed; private double loanAmount; private static final double FEE = 100, PENALTY = 2; // constant values 'belonging' to BankAcc public final String TYPE = "REGULAR"; public double getBalance() throws Exception { System.out.println("Dear " + name + ", please enter your password."); String temp = comingIn.readLine(); String badness = "Sorry, you're not authorised to know this information"; if ( temp.equals(password) ) return balance; System.out.println(badness); return Double.NaN; // a useless value! } public void setBalance(double bal) { balance = bal; } public void spend(double amt) { if (amt <= balance) balance -= amt; else { if (overdraftAllowed) { loanAmount = amt - balance + FEE; balance = 0; System.out.println("We have given you an overdraft"); } else { System.out.println("Sorry, insufficient funds available"); loanAmount = FEE * PENALTY; } } } public void deposit(double amt) { balance += amt; } public void overdraftDecision(boolean ok) { overdraftAllowed = ok; } public BankAcc () { this(0.0); } public BankAcc (double balance) { this(balance, "anon", "secret"); } public BankAcc (String password) { this(0.0, "anon", password); } public BankAcc (double balance, String name, String password) { this.balance = balance; this.name = name; this.password = password; overdraftAllowed = false; comingIn = new BufferedReader(new InputStreamReader(System.in)); numAccsMade++; } }