You are given a class called SavingsAccount
. It has:
- A
long
field calledtotal
. - A
deposit
method that adds to thetotal
. - A
withdraw
method that subtracts the given amount from thetotal
. It returnstrue
if the operation is valid and successful andfalse
otherwise.
The class should work with multiple threads. If multiple threads are operating
on the same instance of SavingsAccount
, the total
must have the correct
value once all the thread operations are completed.
class SavingsAccount {
private long total = 0;
public boolean withdraw(long amount) {
}
public void deposit(long amount) {
}
public long getTotal() {
return total;
}
}