/
msigin77
/
Home_work9_1
Обзор
Документация
Войти
/
msigin77
/
Home_work9_1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
CreditAccount.java
37 строк
1 KB
msigin77
д\з_9
14 дек 2025, 10:45
14 дек 2025, 10:45
cf8136f
Код
Авторство
О чём код?
public class CreditAccount extends Account { private long creditLimit; public CreditAccount(long creditLimit) { if (creditLimit <= 0) { throw new IllegalArgumentException("Кредитный лимит должен быть положительным числом"); } this.creditLimit = creditLimit; this.balance = 0; } @Override public boolean add(long amount) { if (amount <= 0) { return false; // нельзя пополнить на отрицательную сумму или ноль } if (balance + amount > 0) { return false; // нельзя уйти в плюс на кредитном счете } balance += amount; return true; } @Override public boolean pay(long amount) { if (amount <= 0) { return false; // нельзя оплатить отрицательную сумму или ноль } if (balance - amount < -creditLimit) { return false; // превышен кредитный лимит } balance -= amount; return true; } }