Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void addRate(String from, String to, int rate){
- this.rates.put(new Pair(from, to), new Integer(rate));
- }
- @Test
- public void testreduceMoneyDifferentCurrency(){
- Bank bank = new Bank();
- bank.addRate("GBP", "USD", 2);
- Money result = bank.reduce(Money.gbpound(2), "USD");
- assertEquals(Money.dollar(1), result);
- }
- public Money reduce(Bank bank, String to){
- int rate = bank.rate(this.currency, to);
- return new Money(this.amount / rate, to);
- }
- public int rate(String from, String to){
- if (from.equals(to)) return 1;
- Integer rate = (Integer) this.rates.get(new Pair(from, to));
- return rate.intValue();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement