update BanckAccount class

This commit is contained in:
2026-06-10 07:41:45 +03:30
parent f3c9bf8876
commit dd2de9aef0
@@ -35,6 +35,7 @@ public class BankAccount {
public void deposit(long amount) {
lock.writeLock().lock();
try {
if (amount < 0) throw new IllegalArgumentException("Amount cannot be negative");
balance += amount;
}
finally {
@@ -45,6 +46,8 @@ public class BankAccount {
public void withdraw(long amount) {
lock.writeLock().lock();
try {
if (amount < 0) throw new IllegalArgumentException("Amount cannot be negative");
if (balance < amount) throw new IllegalArgumentException("insufficient balance");
balance -= amount;
}
finally {
@@ -61,6 +64,8 @@ public class BankAccount {
try {
second.lock.writeLock().lock();
try {
if (amount < 0) throw new IllegalArgumentException("Amount cannot be negative");
if (amount > balance) throw new IllegalArgumentException("insufficient balance");
this.balance -= amount;
target.balance += amount;
} finally {