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>
50 changes: 50 additions & 0 deletions src/main/java/CurrencyConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.util.HashMap;
import java.text.DecimalFormat;

/**
* Created by Kibret
*/

import java.text.NumberFormat;

public class CurrencyConverter {



private HashMap<String, Float> exchangeRateRecord;


public CurrencyConverter () {
exchangeRateRecord = new HashMap<String, Float>();
exchangeRateRecord.put("USD", 1.00F);
exchangeRateRecord.put("EUR", 0.94F);
exchangeRateRecord.put("GBP", 0.82F);
exchangeRateRecord.put("INR", 68.32F);
exchangeRateRecord.put("AUD", 1.35F);
exchangeRateRecord.put("CAD", 1.32F);
exchangeRateRecord.put("SGD", 1.43F);
exchangeRateRecord.put("CHF", 1.01F);
exchangeRateRecord.put("MYR", 4.47F);
exchangeRateRecord.put("JPY", 115.84F);
exchangeRateRecord.put("CNY", 6.92F);

}


public String currencyConverter(String fromCurrencyCode, String toCurrencyCode, Float amountToConvert) {
DecimalFormat formatter = new DecimalFormat("0.##");
// NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
String result =formatter.format(exchangeRateRecord.get(toCurrencyCode) / (exchangeRateRecord.get(fromCurrencyCode))* amountToConvert);
return result;


}


public HashMap<String, Float> getExchangeRateRecord() {
return exchangeRateRecord;
}
}



Empty file removed src/main/java/DELETEME
Empty file.
103 changes: 103 additions & 0 deletions src/test/java/CurrencyConverterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.HashMap;

public class CurrencyConverterTest {
private static CurrencyConverter tester;

@Before
public void setUp() {
tester = new CurrencyConverter();
}
@Test
public void testCurrencyConverter() {
String expected = "609.76";
String actual = tester.currencyConverter("GBP", "USD", 500.00F);

Assert.assertEquals(expected, actual);
}
@Test
public void dollarToEuro() {
String expected = "470";
String actual = tester.currencyConverter("USD", "EUR", 500.00F);
Assert.assertEquals(expected, actual);
}

@Test
public void euroToDollar() {
String expected = "531.91";
String actual = tester.currencyConverter("EUR", "USD", 500.00F);
Assert.assertEquals(expected, actual);
}

@Test
public void britishPoundToDollar() {
String expected = "609.76";
String actual = tester.currencyConverter("GBP", "USD", 500.00F);
Assert.assertEquals(expected, actual);
}


@Test
public void euroToBritishPound() {
String expected = "436.17";
String actual = tester.currencyConverter("EUR", "GBP", 500.00F);
Assert.assertEquals(expected, actual);
}


@Test
public void britishPoundToIndianRupee() {
String expected = "41658.54";
String actual = tester.currencyConverter("GBP", "INR", 500.00F);
Assert.assertEquals(expected, actual);
}


@Test
public void rupeeToCanadianDollar() {
String expected = "9.66";
String actual = tester.currencyConverter("INR", "CAD", 500.00F);
Assert.assertEquals(expected, actual);
}


@Test
public void canadianDollarToSingaporeDollar() {
String expected = "541.67";
String actual = tester.currencyConverter("CAD", "SGD", 500.00F);
Assert.assertEquals(expected, actual);
}

@Test
public void SingaporeDollarToSwissFranc() {
String expected = "353.15";
String actual = tester.currencyConverter("SGD", "CHF", 500.00F);
Assert.assertEquals(expected, actual);
}

@Test
public void SwissFrancToMalaysianRinggit() {
String expected = "2212.87";
String actual = tester.currencyConverter("CHF", "MYR", 500.00F);
Assert.assertEquals(expected, actual);
}

@Test
public void MalaysianRinggitToJapaneseYen() {
String expected = "12957.5";
String actual = tester.currencyConverter("MYR", "JPY", 500.00F);
Assert.assertEquals(expected, actual);
}

@Test
public void JapaneseYenToChineseYuanRenminbi() {
String expected = "29.87";
String actual = tester.currencyConverter("JPY", "CNY", 500.00F);
Assert.assertEquals(expected, actual);
}


}
Empty file removed src/test/java/DELETEME
Empty file.
Binary file added target/classes/CurrencyConverter.class
Binary file not shown.
Binary file added target/test-classes/CurrencyConverterTest.class
Binary file not shown.