Skip to content
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

first commit #73

Open
wants to merge 3 commits 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
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>
45 changes: 45 additions & 0 deletions src/main/java/CurrencyConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.text.NumberFormat;
import java.util.HashMap;

public class CurrencyConverter {



private HashMap<String, Float> converter;


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

}


public String makeConversion (String fromCurrencyCode, String toCurrencyCode, Float amountToConvert) {
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
String result =currencyFormatter.format(converter.get(toCurrencyCode) / (converter.get(fromCurrencyCode))* amountToConvert);
return result;


}


public static void main(String[] args) {

CurrencyConverter test = new CurrencyConverter();
System.out.println(test.makeConversion("CAD","CHF",200.00F));


}

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

import java.util.HashMap;

import static org.junit.Assert.*;

public class CurrencyConverterTestTest {
private static CurrencyConverter tester;

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



@Test
public void GBP_to_USD() {
String expected = "$609.76";
String actual = tester.makeConversion("GBP", "USD", 500.00F);

Assert.assertEquals(expected, actual);
}


// 1.
@Test
public void USD_to_EUR() {
String expected = "$470.00";
String actual = tester.makeConversion("USD", "EUR", 500.00F);

Assert.assertEquals(expected, actual);
}

// 2.
@Test
public void EUR_to_USD() {
String expected = "$531.91";
String actual = tester.makeConversion("EUR", "USD", 500.00F);

Assert.assertEquals(expected, actual);
}

// 3.
@Test
public void EUR_to_GBP() {
String expected = "$436.17";
String actual = tester.makeConversion("EUR", "GBP", 500.00F);

Assert.assertEquals(expected, actual);
}

// 4.
@Test
public void GBP_to_INR() {
String expected = "$41,658.54";
String actual = tester.makeConversion("GBP", "INR", 500.00F);

Assert.assertEquals(expected, actual);
}

// 5.
@Test
public void INR_to_CAD() {
String expected = "$9.66";
String actual = tester.makeConversion("INR", "CAD", 500.00F);

Assert.assertEquals(expected, actual);
}

// 6.
@Test
public void CAD_to_SGD() {
String expected = "$541.67";
String actual = tester.makeConversion("CAD", "SGD", 500.00F);

Assert.assertEquals(expected, actual);
}

// 7.
@Test
public void SGD_to_CHF() {
String expected = "$353.15";
String actual = tester.makeConversion("SGD", "CHF", 500.00F);

Assert.assertEquals(expected, actual);
}

// 8.
@Test
public void CHF_to_MYR() {
String expected = "$2,212.87";
String actual = tester.makeConversion("CHF", "MYR", 500.00F);

Assert.assertEquals(expected, actual);
}

// 9.
@Test
public void MYR_to_JPY() {
String expected = "$12,957.50";
String actual = tester.makeConversion("MYR", "JPY", 500.00F);

Assert.assertEquals(expected, actual);
}

// 10.
@Test
public void JPY_to_CNY() {
String expected = "$29.87";
String actual = tester.makeConversion("JPY", "CNY", 500.00F);

Assert.assertEquals(expected, actual);
}


}
// Convert Japanese Yen to Chinese Yuan Renminbi
Empty file removed src/test/java/DELETEME
Empty file.
Binary file added target/classes/CurrencyConverter.class
Binary file not shown.
Binary file not shown.
Binary file not shown.