1 package org.apidesign.apifest08.currency;
3 /** This is the skeleton class for your API. You need to make it public, so
4 * it is accessible to your client code (currently in Task1Test.java) file.
6 * Feel free to create additional classes or rename this one, just keep all
7 * the API and its implementation in this package. Do not spread it outside
10 public class Convertor {
12 public static final int FIRST_TO_SECOND = 1;
14 public static final int SECOND_TO_FIRST = 2;
18 private double second;
20 public Convertor(double first, double second) {
25 public double convertFirstToSecond(double value) {
26 return (second / first) * value;
29 public double convertSecondToFirst(double value) {
30 return (first / second) * value;
33 public double convert(double value, int typeOfConvert) {
34 if (FIRST_TO_SECOND == typeOfConvert) {
35 return convertFirstToSecond(value);
36 } else if (SECOND_TO_FIRST == typeOfConvert) {
37 return convertSecondToFirst(value);
39 throw new IllegalArgumentException("Unkown type of convert.");