From 8d48c63a6affcf8614d055683a55bcf6e8c63c95 Mon Sep 17 00:00:00 2001 From: zzu Date: Fri, 30 Sep 2016 16:07:38 +0300 Subject: [PATCH 1/3] Project Finished --- src/RomanNumerals.java | 21 +++- tests/TestRomanNumerals.java | 206 ++++++++++++++++++++++++++++++++++- 2 files changed, 221 insertions(+), 6 deletions(-) diff --git a/src/RomanNumerals.java b/src/RomanNumerals.java index 20904f0..e62aa2c 100644 --- a/src/RomanNumerals.java +++ b/src/RomanNumerals.java @@ -1,8 +1,23 @@ +import java.util.HashMap; public class RomanNumerals { - public int convertToInteger(String romanNum) { - // To be Implemented - return 0; + public static int convertToInteger(String romanNum) { + HashMap hashmap = new HashMap(); + hashmap.put("I", 1); hashmap.put("V", 5); hashmap.put("X", 10); hashmap.put("L", 50); + hashmap.put("C", 100); hashmap.put("D", 500); hashmap.put("M", 1000); hashmap.put("IV", 4); + hashmap.put("IX", 9); hashmap.put("XL", 40); hashmap.put("XC", 90); hashmap.put("CD", 400); hashmap.put("CM", 900); + int result = 0; + int index = 0; + while( index Date: Fri, 30 Sep 2016 16:50:23 +0300 Subject: [PATCH 2/3] Update RomanNumerals.java --- src/RomanNumerals.java | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/RomanNumerals.java b/src/RomanNumerals.java index e62aa2c..1c310ec 100644 --- a/src/RomanNumerals.java +++ b/src/RomanNumerals.java @@ -1,7 +1,14 @@ import java.util.HashMap; - public class RomanNumerals { - public static int convertToInteger(String romanNum) { + public int convertToInteger(String romanNum) throws Exception { + String[] str = new String[6]; + str[0] = "VV"; str[0] = "LL"; str[0] = "DD"; str[0] = "IIII"; str[0] = "XXXX"; str[0] = "CCCC"; + int i=0; + for( i=0 ; i<6 ; i++) + { + if( romanNum.contains(str[i])) + throw new ContainSuccessive_1_Number(); + } HashMap hashmap = new HashMap(); hashmap.put("I", 1); hashmap.put("V", 5); hashmap.put("X", 10); hashmap.put("L", 50); hashmap.put("C", 100); hashmap.put("D", 500); hashmap.put("M", 1000); hashmap.put("IV", 4); @@ -10,14 +17,22 @@ public static int convertToInteger(String romanNum) { int index = 0; while( index Date: Fri, 30 Sep 2016 16:50:48 +0300 Subject: [PATCH 3/3] Update TestRomanNumerals.java --- tests/TestRomanNumerals.java | 124 +++++++++++++++++------------------ 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/tests/TestRomanNumerals.java b/tests/TestRomanNumerals.java index 88f337a..c267629 100644 --- a/tests/TestRomanNumerals.java +++ b/tests/TestRomanNumerals.java @@ -5,208 +5,208 @@ public class TestRomanNumerals { @Test - public void test_I_1() { + public void test_I_1() throws Exception { RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("I"); + int result = RNs.convertToInteger("I"); assertEquals(1,result); } @Test - public void test_II_2() { + public void test_II_2() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("II"); + int result = RNs.convertToInteger("II"); assertEquals(2,result); } @Test - public void test_III_3() { + public void test_III_3() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("III"); + int result = RNs.convertToInteger("III"); assertEquals(3,result); } @Test - public void test_IV_4() { + public void test_IV_4() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("IV"); + int result = RNs.convertToInteger("IV"); assertEquals(4,result); } @Test - public void test_V_5() { + public void test_V_5() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("V"); + int result = RNs.convertToInteger("V"); assertEquals(5,result); } @Test - public void test_VI_6() { + public void test_VI_6() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("VI"); + int result = RNs.convertToInteger("VI"); assertEquals(6,result); } @Test - public void test_VII_7() { + public void test_VII_7() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("VII"); + int result = RNs.convertToInteger("VII"); assertEquals(7,result); } @Test - public void test_VIII_8() { + public void test_VIII_8() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("VIII"); + int result = RNs.convertToInteger("VIII"); assertEquals(8,result); } @Test - public void test_IX_9() { + public void test_IX_9() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("IX"); + int result = RNs.convertToInteger("IX"); assertEquals(9,result); } @Test - public void test_X_10() { + public void test_X_10() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("X"); + int result = RNs.convertToInteger("X"); assertEquals(10,result); } @Test - public void test_XI_11() { + public void test_XI_11() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("XI"); + int result = RNs.convertToInteger("XI"); assertEquals(11,result); } @Test - public void test_XX_20() { + public void test_XX_20() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("XX"); + int result = RNs.convertToInteger("XX"); assertEquals(20,result); } @Test - public void test_XXX_30() { + public void test_XXX_30() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("XXX"); + int result = RNs.convertToInteger("XXX"); assertEquals(30,result); } @Test - public void test_XL_40() { + public void test_XL_40() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("XL"); + int result = RNs.convertToInteger("XL"); assertEquals(40,result); } @Test - public void test_L_50() { + public void test_L_50() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("L"); + int result = RNs.convertToInteger("L"); assertEquals(50,result); } @Test - public void test_LX_60() { + public void test_LX_60() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("LX"); + int result = RNs.convertToInteger("LX"); assertEquals(60,result); } @Test - public void test_LXX_70() { + public void test_LXX_70() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("LXX"); + int result = RNs.convertToInteger("LXX"); assertEquals(70,result); } @Test - public void test_LXXX_80() { + public void test_LXXX_80() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("LXXX"); + int result = RNs.convertToInteger("LXXX"); assertEquals(80,result); } @Test - public void test_XC_90() { + public void test_XC_90() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("XC"); + int result = RNs.convertToInteger("XC"); assertEquals(90,result); } @Test - public void test_C_100() { + public void test_C_100() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("C"); + int result = RNs.convertToInteger("C"); assertEquals(100,result); } @Test - public void test_CC_200() { + public void test_CC_200() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("CC"); + int result = RNs.convertToInteger("CC"); assertEquals(200,result); } @Test - public void test_CCC_300() { + public void test_CCC_300() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("CCC"); + int result = RNs.convertToInteger("CCC"); assertEquals(300,result); } @Test - public void test_CD_400() { + public void test_CD_400() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("CD"); + int result = RNs.convertToInteger("CD"); assertEquals(400,result); } @Test - public void test_D_500() { + public void test_D_500() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("D"); + int result = RNs.convertToInteger("D"); assertEquals(500,result); } @Test - public void test_DC_600() { + public void test_DC_600() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("DC"); + int result = RNs.convertToInteger("DC"); assertEquals(600,result); } @Test - public void test_DCC_700() { + public void test_DCC_700() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("DCC"); + int result = RNs.convertToInteger("DCC"); assertEquals(700,result); } @Test - public void test_DCCC_800() { + public void test_DCCC_800() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("DCCC"); + int result = RNs.convertToInteger("DCCC"); assertEquals(800,result); } @Test - public void test_CM_900() { + public void test_CM_900() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("CM"); + int result = RNs.convertToInteger("CM"); assertEquals(900,result); } @Test - public void test_M_1000() { + public void test_M_1000() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("M"); + int result = RNs.convertToInteger("M"); assertEquals(1000,result); } @Test - public void test_MCMLXXXIV_1984() { + public void test_MCMLXXXIV_1984() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("MCMLXXXIV"); + int result = RNs.convertToInteger("MCMLXXXIV"); assertEquals(1984,result); } @Test - public void test_MMXIV_2014() { + public void test_MMXIV_2014() throws Exception{ RomanNumerals RNs = new RomanNumerals(); - int result = RomanNumerals.convertToInteger("MMXIV"); + int result = RNs.convertToInteger("MMXIV"); assertEquals(2014,result); } }