...
Блок кода | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
package org.mai.dep810.cer; import java.math.BigDecimal; import java.util.Currency; public class CurrencyExchangeRate { BigDecimal rate; Currency from; Currency to; public CurrencyExchangeRate(BigDecimal rate, Currency from, Currency to) { this.rate = rate; this.from = from; this.to = to; } public Money convert(Money m) { if(m.getCurrency().equals(from)) { return new Money(to, m.getAmount().multiply(rate)); } else { throw new IncorrectExchangeRateException("Unable to convert currency "+m.getCurrency().getCurrencyCode() + " from "+from.getCurrencyCode()); } } } |
Стандартная библиотека коллекций
Tutorial: https://docs.oracle.com/javase/tutorial/collections/index.html
Альтернативные библиотеки коллекций
...