Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
Empty file removed src/main/java/DELETEME
Empty file.
40 changes: 40 additions & 0 deletions src/main/java/com/zipcodewilmington/ExchangeRate/ExchangeRate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.zipcodewilmington.ExchangeRate;

public enum ExchangeRate {
USD(1.00f),
GBP(0.82f),
EUR(0.94f),
INR(68.32f),
AUD(1.35f),
CAD(1.32f),
SGD(1.43f),
CHF(1.01f),
MYR(4.47f),
JPY(115.84f),
CNY(6.92f);

public double rate;

public double getRate() {
return rate;
}

public void setRate(double rate) {
this.rate = rate;
}

ExchangeRate(double rate) {
this.rate = rate;
}

public static double conversion(double beginningCurrencyAmount, ExchangeRate beginningCurrency, ExchangeRate endingCurrency) {
double fromExchangeRate = beginningCurrency.getRate(); //USD
double toExchangeRate = endingCurrency.getRate(); //Euro
double conversionRate = toExchangeRate / fromExchangeRate; //Euro/USD
double convertedCurrency = conversionRate * beginningCurrencyAmount;

return convertedCurrency;

}

}
Empty file removed src/test/java/DELETEME
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.zipcodewilmington.ExchangeRate;


import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ExchangeRateTest {

// private ExchangeRate testExchangeRate;
double currentCurrency = 1;
public static final double delta = 0.01;
ExchangeRate USD = ExchangeRate.USD;
ExchangeRate GBP = ExchangeRate.GBP;
ExchangeRate EUR = ExchangeRate.EUR;
ExchangeRate INR = ExchangeRate.INR;
ExchangeRate AUD = ExchangeRate.AUD;
ExchangeRate CAD = ExchangeRate.CAD;
ExchangeRate SGD = ExchangeRate.SGD;
ExchangeRate CHF = ExchangeRate.CHF;
ExchangeRate MYR = ExchangeRate.MYR;
ExchangeRate JPY = ExchangeRate.JPY;
ExchangeRate CNY = ExchangeRate.CNY;


@Test
public void testUSDToEuro() {

double expected = .94;
double actual = ExchangeRate.conversion(currentCurrency, USD, EUR);
Assert.assertEquals(expected, actual, delta);

}

@Test
public void testEuroToUSD() {

double expected = 1.06;
double actual = ExchangeRate.conversion(currentCurrency, EUR, USD);
Assert.assertEquals(expected, actual, delta);

}

@Test
public void testEuroToGBP() {

double expected = .87;
double actual = ExchangeRate.conversion(currentCurrency, EUR, GBP);
Assert.assertEquals(expected, actual, delta);
}
@Test
public void testCNYToJPY() {

double expected = 16.73;
double actual = ExchangeRate.conversion(currentCurrency, CNY, JPY);
Assert.assertEquals(expected, actual, delta);
}
@Test
public void testJPYToCNY() {

double expected = 0.05;
double actual = ExchangeRate.conversion(currentCurrency, JPY, CNY);
Assert.assertEquals(expected, actual, delta);
}

@Test
public void testINRToCAD() {

double expected = .019;
double actual = ExchangeRate.conversion(currentCurrency, INR, CAD);
Assert.assertEquals(expected, actual, delta);
}
@Test
public void testAUDToSGD() {

double expected = 1.05;
double actual = ExchangeRate.conversion(currentCurrency, AUD, SGD);
Assert.assertEquals(expected, actual, delta);
}
@Test
public void testCHFToMYR() {

double expected = 4.42;
double actual = ExchangeRate.conversion(currentCurrency, CHF, MYR);
Assert.assertEquals(expected, actual, delta);
}
}
Binary file not shown.
Binary file not shown.