Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public void addRate(String from, String to, int rate){
  2. this.rates.put(new Pair(from, to), new Integer(rate));
  3. }
  4.  
  5. @Test
  6. public void testreduceMoneyDifferentCurrency(){
  7. Bank bank = new Bank();
  8. bank.addRate("GBP", "USD", 2);
  9. Money result = bank.reduce(Money.gbpound(2), "USD");
  10. assertEquals(Money.dollar(1), result);
  11. }
  12.  
  13. public Money reduce(Bank bank, String to){
  14. int rate = bank.rate(this.currency, to);
  15. return new Money(this.amount / rate, to);
  16. }
  17.  
  18. public int rate(String from, String to){
  19. if (from.equals(to)) return 1;
  20. Integer rate = (Integer) this.rates.get(new Pair(from, to));
  21. return rate.intValue();
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement