/
Nikitiko
/
12
Обзор
Документация
Войти
/
Nikitiko
/
12
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
78 строк
2 KB
Nikitiko
upload files
07 окт 2025, 18:21
07 окт 2025, 18:21
49f2007
Код
Авторство
О чём код?
abstract class Account { protected long balance; // Текущий баланс счета public Account(long initialBalance) { this.balance = initialBalance; } public long getBalance() { return balance; } public abstract boolean add(long amount); public abstract boolean pay(long amount); public boolean transfer(Account account, long amount) { if (this.pay(amount)) { if (account.add(amount)) { return true; } else { this.add(amount); return false; } } return false; } } class SimpleAccount extends Account { public SimpleAccount(long initialBalance) { super(initialBalance); } @Override public boolean add(long amount) { if (amount > 0) { balance += amount; return true; } return false; } @Override public boolean pay(long amount) { if (amount > 0 && balance >= amount) { balance -= amount; return true; } return false; } } class CreditAccount extends Account { private long creditLimit; public CreditAccount(long initialBalance, long creditLimit) { super(initialBalance); this.creditLimit = creditLimit; } @Override public boolean add(long amount) { if (amount > 0 && balance < 0) { balance += amount; return true; } return false; } @Override public boolean pay(long amount) { if (amount > 0 && (balance - amount) >= -creditLimit) { balance -= amount; return true; } return false; } }