← all problems

BankAccount.deposit

Below is a partially written BankAccount class. It already has a balance field and a constructor that sets the starting balance. Write the deposit method: given a non-negative amount, add it to the account's balance and return the new balance. For example, if the account's balance is 100.0, calling deposit(50.0) should return 150.0.

BankAccount.java — the class below is already written; you're only completing the method in the editable box.

class BankAccount {
    private double balance;

    public BankAccount(double startingBalance) {
        balance = startingBalance;
    }
    // ---- write your method below ----
}