/** * Working with the Bank class, this class kind of does a passbook savings * account vibe. * * @author gtowell * Created: Nov 2023 */ public class BankAccount { private final String accountNumber; private String name; private double balance; public BankAccount(String name, String actNo, double startDep) { this.accountNumber = actNo; this.name = name; this.balance = startDep; } public void changeName(String newName) { this.name = newName; } // alternately, it would make sense to return new balance // in this case, true means the deposit was taken. public boolean deposit(double dep) { if (dep < 0) { System.out.println("Cannot make a negative deposit"); return false; } if (dep > 10000) { System.out.println("No. Would have to report this to the Treasury"); return false; } balance += dep; return true; } // alternately, it would make sense to return new balance // in this case, true means the deposit was taken. // Alternately, throw exception if withdrawal is too big public boolean withdrawal(double withdrawal) { if (withdrawal < 0) { System.out.println("Cannot make a negative withdrawal"); return false; } if ((balance - withdrawal) < 0) { System.out.println("Not enough money"); return false; } balance -= withdrawal; return true; } public double getBalance() { return balance; } public String getName() { return name; } public String getAccountNumber() { return accountNumber; } public String toString() { return accountNumber + " " + name + " balance:" + balance; } }