public class BankAccount {

    // 1. instance variables
    // balance, name, account type, account #
    private double balance;

    // 2. constructor
    public BankAccount(double initialAmount) {
        balance = initialAmount;
    }

    // 3. methods (public method become public interface)

    // viewBalance
    public double getBalance() {
        return balance;
        // this is exactly the same as:
        // return this.balance;
    }

    // deposit
    public void deposit(double amount) {
        if (isInvalidAmount(amount)) {
            System.out.println("Invalid amount to deposit");
            return;
        }
        balance = balance + amount;
    }

    // withdraw
    // returns the amount withdrawn
    public double withdraw(double amount) {
        if (isInvalidAmount(amount)) {
            System.out.println("Invalid amount to take out");
            return 0;
        } else if (amount > balance) {
            System.out.println("Can't take more than you have");
            return 0;
        } else {
            balance = balance - amount;
            return amount;
        }
    }

    // helper method, left private since not useful
    // outside of this class.
    private boolean isInvalidAmount(double amount) {
        return amount < 0;
    }

}
