japod@25: japod@25: package org.apidesign.apifest08.currency; japod@25: japod@25: public final class Rate { japod@25: japod@25: private double rate; japod@25: japod@25: public Rate(int amountA, int amountB) { japod@25: rate = amountA / (double)amountB; japod@25: if (rate <= 0) { japod@25: throw new IllegalArgumentException("Exchange rate must be positive."); japod@25: } japod@25: } japod@25: japod@25: public Rate(double amountA, double amountB) { japod@25: rate = amountA / amountB; japod@25: if (rate <= 0) { japod@25: throw new IllegalArgumentException("Exchange rate must be positive."); japod@25: } japod@25: } japod@25: japod@25: public Rate(double rate) { japod@25: this.rate = rate; japod@25: if (this.rate <= 0) { japod@25: throw new IllegalArgumentException("Exchange rate must be positive."); japod@25: } japod@25: } japod@25: japod@25: public double convertAtoB(int a) { japod@25: return a / rate; japod@25: } japod@25: japod@25: public double convertAtoB(double a) { japod@25: return a / rate; japod@25: } japod@25: japod@25: public double convertBtoA(int b) { japod@25: return b * rate; japod@25: } japod@25: japod@25: public double convertBtoA(double b) { japod@25: return b * rate; japod@25: } japod@25: japod@25: japod@25: @Override japod@25: public boolean equals(Object obj) { japod@25: if (obj == null) { japod@25: return false; japod@25: } japod@25: if (getClass() != obj.getClass()) { japod@25: return false; japod@25: } japod@25: final Rate other = (Rate) obj; japod@25: return true; japod@25: } japod@25: japod@25: @Override japod@25: public int hashCode() { japod@25: int hash = 5; japod@25: return hash; japod@25: } japod@25: japod@25: @Override japod@25: public String toString() { japod@25: return ""+rate; japod@25: } japod@25: }