/
digit
/
java-oop-polymorphism-abstract
Обзор
Документация
Войти
/
digit
/
java-oop-polymorphism-abstract
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task1/Account.java
43 строки
1 KB
digit
Create: Account.java, CreditAccount.java, Main.java, SimpleAccount.java, Logger.java, Main.java, SimpleLogger.java, SmartLogger.java
09 июл 2026, 16:50
Верифицирован
09 июл 2026, 16:50
e09293a
Код
Авторство
О чём код?
package task1; public abstract class Account { protected long balance; public Account() { this.balance = 0; } public Account(long balance) { this.balance = balance; } public long getBalance() { return balance; } public boolean add(long amount) { if (amount < 0) { return false; } balance += amount; return true; } // абстрактный метод для реализации в task1.SimpleAccount и task1.CreditAccount public abstract boolean pay(long amount); public boolean transfer(Account account, long amount) { if (account == null || amount < 0) { // проверка аккаунта на null и суммы amount return false; } if (!this.pay(amount)) { // используется pay() return false; } if (!account.add(amount)) { // используется add() this.add(amount); // отмена операции при неудаче return false; } return true; } }