task4/solution14/src/org/apidesign/apifest08/currency/Rate.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 11 Oct 2008 23:38:46 +0200
changeset 61 58ec6da75f6f
parent 50 task3/solution14/src/org/apidesign/apifest08/currency/Rate.java@03c5c5dc94e7
permissions -rw-r--r--
Copying structure for task4
     1 
     2 package org.apidesign.apifest08.currency;
     3 
     4 public final class Rate {
     5 
     6     private double rate;
     7 
     8     public Rate(int amountA, int amountB) {
     9         rate = amountA / (double)amountB;
    10         if (rate <= 0) {
    11             throw new IllegalArgumentException("Exchange rate must be positive.");
    12         }
    13     }
    14 
    15     public Rate(double amountA, double amountB) {
    16         rate = amountA / amountB;
    17         if (rate <= 0) {
    18             throw new IllegalArgumentException("Exchange rate must be positive.");
    19         }
    20     }
    21     
    22     public Rate(double rate) {
    23         this.rate = rate;
    24         if (this.rate <= 0) {
    25             throw new IllegalArgumentException("Exchange rate must be positive.");
    26         }
    27     }
    28 
    29     public double convertAtoB(int a) {
    30         return a / rate;
    31     }
    32 
    33     public double convertAtoB(double a) {
    34         return a / rate;
    35     }
    36 
    37     public double convertBtoA(int b) {
    38         return b * rate;
    39     }
    40 
    41     public double convertBtoA(double b) {
    42         return b * rate;
    43     }
    44 
    45 
    46     @Override
    47     public boolean equals(Object obj) {
    48         if (obj == null) {
    49             return false;
    50         }
    51         if (getClass() != obj.getClass()) {
    52             return false;
    53         }
    54         final Rate other = (Rate) obj;
    55         return true;
    56     }
    57 
    58     @Override
    59     public int hashCode() {
    60         int hash = 5;
    61         return hash;
    62     }
    63 
    64     @Override
    65     public String toString() {
    66         return ""+rate;
    67     }
    68 }