Your question is Implementing Class Member Functions. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
At One, a backend engineer is asked to implement and review the member functions of the Pocket class, which models a sub-balance ("pocket") inside a customer's banking app account and backs the deposit/withdraw/interest endpoints. Here is a first draft a teammate put up for review:
public class Pocket {
private String name;
private double balance;
public Pocket(String name, double initialBalance) {
this.name = name;
this.balance = initialBalance;
}
public void deposit(double amount) {
balance += amount;
}
public boolean withdraw(double amount) {
if (amount > balance) {
return false;
}
balance -= amount;
return true;
}
public double applyMonthlyInterest(double annualRatePercent) {
double monthlyRate = annualRatePercent / 12;
balance += balance * monthlyRate;
return balance;
}
public double getBalance() {
return balance;
}
}
Walk through how you'd implement these member functions correctly for a production banking backend, and identify every issue with this draft before it ships.