author | japod@localhost |
Tue, 30 Sep 2008 16:11:32 +0200 | |
changeset 28 | 36331f7244bd |
permissions | -rw-r--r-- |
japod@6 | 1 |
package org.apidesign.apifest08.currency; |
japod@6 | 2 |
|
japod@6 | 3 |
/** This is the skeleton class for your API. You need to make it public, so |
japod@6 | 4 |
* it is accessible to your client code (currently in Task1Test.java) file. |
japod@6 | 5 |
* <p> |
japod@6 | 6 |
* Feel free to create additional classes or rename this one, just keep all |
japod@6 | 7 |
* the API and its implementation in this package. Do not spread it outside |
japod@6 | 8 |
* to other packages. |
japod@6 | 9 |
*/ |
japod@6 | 10 |
public class Convertor { |
japod@6 | 11 |
|
japod@6 | 12 |
public static final int FIRST_TO_SECOND = 1; |
japod@6 | 13 |
|
japod@6 | 14 |
public static final int SECOND_TO_FIRST = 2; |
japod@6 | 15 |
|
japod@6 | 16 |
private double first; |
japod@6 | 17 |
|
japod@6 | 18 |
private double second; |
japod@6 | 19 |
|
japod@6 | 20 |
public Convertor(double first, double second) { |
japod@6 | 21 |
this.first = first; |
japod@6 | 22 |
this.second = second; |
japod@6 | 23 |
} |
japod@6 | 24 |
|
japod@6 | 25 |
public double convertFirstToSecond(double value) { |
japod@6 | 26 |
return (second / first) * value; |
japod@6 | 27 |
} |
japod@6 | 28 |
|
japod@6 | 29 |
public double convertSecondToFirst(double value) { |
japod@6 | 30 |
return (first / second) * value; |
japod@6 | 31 |
} |
japod@6 | 32 |
|
japod@6 | 33 |
public double convert(double value, int typeOfConvert) { |
japod@6 | 34 |
if (FIRST_TO_SECOND == typeOfConvert) { |
japod@6 | 35 |
return convertFirstToSecond(value); |
japod@6 | 36 |
} else if (SECOND_TO_FIRST == typeOfConvert) { |
japod@6 | 37 |
return convertSecondToFirst(value); |
japod@6 | 38 |
} |
japod@6 | 39 |
throw new IllegalArgumentException("Unkown type of convert."); |
japod@6 | 40 |
} |
japod@6 | 41 |
} |