diff -r 03c5c5dc94e7 -r 58ec6da75f6f task4/solution14/src/org/apidesign/apifest08/currency/Rate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/task4/solution14/src/org/apidesign/apifest08/currency/Rate.java Sat Oct 11 23:38:46 2008 +0200 @@ -0,0 +1,68 @@ + +package org.apidesign.apifest08.currency; + +public final class Rate { + + private double rate; + + public Rate(int amountA, int amountB) { + rate = amountA / (double)amountB; + if (rate <= 0) { + throw new IllegalArgumentException("Exchange rate must be positive."); + } + } + + public Rate(double amountA, double amountB) { + rate = amountA / amountB; + if (rate <= 0) { + throw new IllegalArgumentException("Exchange rate must be positive."); + } + } + + public Rate(double rate) { + this.rate = rate; + if (this.rate <= 0) { + throw new IllegalArgumentException("Exchange rate must be positive."); + } + } + + public double convertAtoB(int a) { + return a / rate; + } + + public double convertAtoB(double a) { + return a / rate; + } + + public double convertBtoA(int b) { + return b * rate; + } + + public double convertBtoA(double b) { + return b * rate; + } + + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Rate other = (Rate) obj; + return true; + } + + @Override + public int hashCode() { + int hash = 5; + return hash; + } + + @Override + public String toString() { + return ""+rate; + } +}