/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/java/java-503-101-005/main.java
25 строк
743 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
// Хорошо: неизменяемый класс public final class Money { private final BigDecimal amount; private final Currency currency; public Money(BigDecimal amount, Currency currency) { this.amount = amount.setScale(2, RoundingMode.HALF_UP); this.currency = Objects.requireNonNull(currency); } public Money add(Money other) { if (!this.currency.equals(other.currency)) { throw new IllegalArgumentException("Currencies must match"); } return new Money(this.amount.add(other.amount), this.currency); } public BigDecimal getAmount() { return amount; } public Currency getCurrency() { return currency; } }