/
Irelion
/
tdd
Обзор
Документация
Войти
/
Irelion
/
tdd
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/example/Money.java
59 строк
1 KB
irelion
TDD-0005: add task 16
17 фев 2026, 15:22
17 фев 2026, 15:22
64001b2
Код
Авторство
О чём код?
package example; import static example.Currency.*; class Money implements Expression{ protected int amount; protected String currency; public Expression times(int multiplier){ return new Money(this.amount * multiplier, currency); }; protected Money(int amount, final String currency) { this.amount = amount; this.currency = currency; } public String currency(){ return this.currency; } //Фабрика Доллара static Money dollar(int amount) { return new Money(amount, DOLLAR.getCurrency()); } //Фабрика Франка static Money franc(int amount) { return new Money(amount, FRANC.getCurrency()); } @Override public Expression plus(final Expression addend) { return new Sum(this, addend); } @Override public Money reduce(final Bank bank, final String to) { int rate = bank.rate(currency, to); return new Money(amount / rate, to); } @Override public String toString() { return "Money{" + "amount=" + amount + ", currency='" + currency + '\'' + '}'; } @Override public boolean equals(final Object object) { Money money = (Money) object; return this.amount == money.amount && currency().equals(money.currency()); } }