Skip to content

I'll try the enum later #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
22 changes: 21 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,33 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.12</modelVersion>

<groupId>io.zipcoder</groupId>
<artifactId>wu-tang-financial</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
24 changes: 24 additions & 0 deletions src/main/java/ExchangeRate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.text.DecimalFormat;

public class ExchangeRate {

static double USD = 1.00;
static double EUR = 0.94; //Euro
static double GBP = 0.82; //British Pound
static double INR = 68.32; //Indian Rupee
static double AUD = 1.35; //Austrailian Dollar
static double CAD = 1.32; //Canadian Dollar
static double SGD = 1.43; //Singapore Dollar
static double CHF = 1.01; //Swiss Franc
static double MYR = 4.47; //Malaysian Ringgit
static double JPY = 115.84; //Japanese Yen
static double CNY = 6.92; //Chinese Yuan Renminbi

public static double convert(double InitialAmount, double initialCurrency, double targetCurrency) {
//Amount will be standardized at USD
double converted = (InitialAmount/initialCurrency) * targetCurrency;
DecimalFormat rounded = new DecimalFormat("#.00");
return Double.parseDouble(rounded.format(converted));
}

}
84 changes: 84 additions & 0 deletions src/test/java/ExchangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;

public class ExchangeTest {

public double initialAmount;

@Before
public void amountInitializer() {
initialAmount = 1.00; //USD
}

@Test
public void dollarToEuro() {
double expected = 0.94;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.USD, ExchangeRate.EUR);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void euroToDollar() {
double expected = 1.06;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.EUR, ExchangeRate.USD);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void euroToPound() {
double expected = 0.87;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.EUR, ExchangeRate.GBP);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void poundToRupee() {
double expected = 83.32;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.GBP, ExchangeRate.INR);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void rupeeToCanadianDollar() {
double expected = 0.02;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.INR, ExchangeRate.CAD);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void canadianDollarToSingaporeDollar() {
double expected = 1.08;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.CAD, ExchangeRate.SGD);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void singaporeDollarToFranc() {
double expected = 0.71;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.SGD, ExchangeRate.CHF);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void francToRinggit() {
double expected = 4.43;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.CHF, ExchangeRate.MYR);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void ringgitToYen() {
double expected = 1.55;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.MYR, ExchangeRate.CNY);
Assert.assertEquals(expected, actual, 0.001);

}

@Test
public void yenToRenminbi() {
double expected = 0.06;
double actual = ExchangeRate.convert(initialAmount, ExchangeRate.JPY, ExchangeRate.CNY);
Assert.assertEquals(expected, actual, 0.001);
}
}
Binary file added target/classes/ExchangeRate.class
Binary file not shown.
Binary file added target/test-classes/ExchangeTest.class
Binary file not shown.