From b7e4279d3e1b9bc1bc420af1221d6e4a8d650496 Mon Sep 17 00:00:00 2001 From: gimenezr Date: Tue, 20 Jan 2015 15:17:04 -0300 Subject: [PATCH 1/4] Topic 2 - Ejer 3 --- fixedexercise2.3/pom.xml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 fixedexercise2.3/pom.xml diff --git a/fixedexercise2.3/pom.xml b/fixedexercise2.3/pom.xml new file mode 100644 index 00000000..f8ab885e --- /dev/null +++ b/fixedexercise2.3/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + ar.com.roberta.mymavenproject + test + jar + 1.0-SNAPSHOT + test + http://maven.apache.org + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + All source code is made available under the terms of the Apache Software License 2.0 + + + + + junit + junit + 3.8.1 + test + + com.google.code.maven-play-plugin.org.playframework + jj-simplecaptcha + 1.1 + + + + + + + + org.apache.maven.plugins + maven-site-plugin + 3.4 + + + + From 929302a02a50cba266ed5095cd3ad364cbc168f2 Mon Sep 17 00:00:00 2001 From: gimenezr Date: Tue, 20 Jan 2015 16:04:11 -0300 Subject: [PATCH 2/4] delete --- fixedexercise2.3/pom.xml | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 fixedexercise2.3/pom.xml diff --git a/fixedexercise2.3/pom.xml b/fixedexercise2.3/pom.xml deleted file mode 100644 index f8ab885e..00000000 --- a/fixedexercise2.3/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - 4.0.0 - ar.com.roberta.mymavenproject - test - jar - 1.0-SNAPSHOT - test - http://maven.apache.org - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - All source code is made available under the terms of the Apache Software License 2.0 - - - - - junit - junit - 3.8.1 - test - - com.google.code.maven-play-plugin.org.playframework - jj-simplecaptcha - 1.1 - - - - - - - - org.apache.maven.plugins - maven-site-plugin - 3.4 - - - - From 373ed8017dc7cf0bc73eed190644ad5c5a3fc2d1 Mon Sep 17 00:00:00 2001 From: gimenezr Date: Sat, 24 Jan 2015 15:09:53 -0300 Subject: [PATCH 3/4] Topic 3-Ejer 4 --- exercise3.4/RomanNumber.java | 58 ++++++++++ exercise3.4/RomanNumberConversion.java | 120 +++++++++++++++++++++ exercise3.4/RomanNumberConversionTest.java | 72 +++++++++++++ 3 files changed, 250 insertions(+) create mode 100644 exercise3.4/RomanNumber.java create mode 100644 exercise3.4/RomanNumberConversion.java create mode 100644 exercise3.4/RomanNumberConversionTest.java diff --git a/exercise3.4/RomanNumber.java b/exercise3.4/RomanNumber.java new file mode 100644 index 00000000..ae268197 --- /dev/null +++ b/exercise3.4/RomanNumber.java @@ -0,0 +1,58 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package romannumberconversion; + +/** + * + * @author roberta + */ +public enum RomanNumber { + + I(1), + V(5), + X(10), + L(50), + C(100), + D(500), + M(1000); + + private final int value; + + RomanNumber(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } + + /** + * Devuelve el valor numérico de la letra romana + * + * @param l + * @return + */ + public static int parse(char l) { + switch (l) { + case 'I': + return I.value; + case 'V': + return V.value; + case 'X': + return X.value; + case 'L': + return L.value; + case 'C': + return C.value; + case 'D': + return D.value; + case 'M': + return M.value; + default: + throw new IllegalArgumentException("Not a romand symbol!"); + } + } +} diff --git a/exercise3.4/RomanNumberConversion.java b/exercise3.4/RomanNumberConversion.java new file mode 100644 index 00000000..97710c32 --- /dev/null +++ b/exercise3.4/RomanNumberConversion.java @@ -0,0 +1,120 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package romannumberconversion; + +/** + * + * @author roberta + */ +public class RomanNumberConversion { + + private String romanNumber; + + + + public static String decToRoman(int dec) { + if (dec <= 0) { + return " There isn't zero in Roman number System"; + } + String resul = ""; + while (dec >= 1000) { + resul += "M"; + dec -= 1000; + } + while (dec >= 900) { + resul += "CM"; + dec -= 900; + } + while (dec >= 500) { + resul += "D"; + dec -= 500; + } + while (dec >= 400) { + resul += "CD"; + dec -= 400; + } + while (dec >= 100) { + resul += "C"; + dec -= 100; + } + while (dec >= 90) { + resul += "XC"; + dec -= 90; + } + while (dec >= 50) { + resul += "L"; + dec -= 50; + } + while (dec >= 40) { + resul += "XL"; + dec -= 40; + } + while (dec >= 10) { + resul += "X"; + dec -= 10; + } + while (dec >= 9) { + resul += "IX"; + dec -= 9; + } + while (dec >= 5) { + resul += "V"; + dec -= 5; + } + while (dec >= 4) { + resul += "IV"; + dec -= 4; + } + while (dec >= 1) { + resul += "I"; + dec -= 1; + } + + return resul; + + } + // Returns a string containing the entered Roman numeral in numeral form. + public String romanToDec(String s) { + + + + int resul = 0; + int last_digit = 0; + int current_digit = 0; + + for (int i = 0; i < s.length(); i++) { + current_digit = RomanNumber.parse(s.charAt(i)); + + + //This is the tricky part. + //If the last number is smaller than the curren number, subtract the last number from the current number + //Otherwise, just add the current number. We must also skip the first number from this rule simply because + //e.g. someone enters 1799 in which case it would subtract 1 from 7 + + if (last_digit < current_digit && last_digit != 0) { + current_digit -= last_digit; + resul -= last_digit; + resul += current_digit; + last_digit = current_digit; + current_digit = 0; + } else { + last_digit = current_digit; + resul += current_digit; + current_digit = 0; + } + } + + + return String.valueOf(resul); + + + } + + + + + +} diff --git a/exercise3.4/RomanNumberConversionTest.java b/exercise3.4/RomanNumberConversionTest.java new file mode 100644 index 00000000..3b0f34fc --- /dev/null +++ b/exercise3.4/RomanNumberConversionTest.java @@ -0,0 +1,72 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package romannumberconversion; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author roberta + */ +public class RomanNumberConversionTest { + + public RomanNumberConversionTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + + + /** + * Test of decToRoman method, of class RomanNumberConversion. + */ + @Test + public void testDecToRoman() { + System.out.println("decToRoman"); + int dec = 5; + String expResult = "V"; + String result = RomanNumberConversion.decToRoman(dec); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + //fail("The test case is a prototype."); + } + + /** + * Test of toArabic method, of class RomanNumberConversion. + */ + @Test + public void testToArabic() { + System.out.println("toArabic"); + String s = "XXI"; + RomanNumberConversion instance = new RomanNumberConversion(); + String expResult = "21"; + String result = instance.romanToDec(s); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + // fail("The test case is a prototype."); + } + +} From 134022f25760d23053be6cb73853584a076e1339 Mon Sep 17 00:00:00 2001 From: gimenezr Date: Wed, 28 Jan 2015 20:13:09 -0300 Subject: [PATCH 4/4] [Topic 3 - Ejer 4] improvements --- exercise3.4/RomanNumber.java | 26 ++---- exercise3.4/RomanNumberConversion.java | 97 ++++++++++------------ exercise3.4/RomanNumberConversionTest.java | 6 +- 3 files changed, 53 insertions(+), 76 deletions(-) diff --git a/exercise3.4/RomanNumber.java b/exercise3.4/RomanNumber.java index ae268197..b79e9bbf 100644 --- a/exercise3.4/RomanNumber.java +++ b/exercise3.4/RomanNumber.java @@ -35,24 +35,14 @@ public int getValue() { * @param l * @return */ - public static int parse(char l) { - switch (l) { - case 'I': - return I.value; - case 'V': - return V.value; - case 'X': - return X.value; - case 'L': - return L.value; - case 'C': - return C.value; - case 'D': - return D.value; - case 'M': - return M.value; - default: - throw new IllegalArgumentException("Not a romand symbol!"); + public static int parse(String l) { + for (RomanNumber r : RomanNumber.values()) { + if (r.toString().equals(l)) { + return r.value; + } } + + throw new IllegalArgumentException("Not a romand symbol!"); + } } diff --git a/exercise3.4/RomanNumberConversion.java b/exercise3.4/RomanNumberConversion.java index 97710c32..cf30f587 100644 --- a/exercise3.4/RomanNumberConversion.java +++ b/exercise3.4/RomanNumberConversion.java @@ -13,108 +13,97 @@ public class RomanNumberConversion { private String romanNumber; - - public static String decToRoman(int dec) { if (dec <= 0) { return " There isn't zero in Roman number System"; } - String resul = ""; + StringBuilder resul = new StringBuilder(); while (dec >= 1000) { - resul += "M"; + resul.append("M"); dec -= 1000; } while (dec >= 900) { - resul += "CM"; + resul.append("CM"); dec -= 900; } while (dec >= 500) { - resul += "D"; + resul.append("D"); dec -= 500; } while (dec >= 400) { - resul += "CD"; + resul.append("CD"); dec -= 400; } while (dec >= 100) { - resul += "C"; + resul.append("C"); dec -= 100; } while (dec >= 90) { - resul += "XC"; + resul.append("XC"); dec -= 90; } while (dec >= 50) { - resul += "L"; + resul.append("L"); dec -= 50; } while (dec >= 40) { - resul += "XL"; + resul.append("XL"); dec -= 40; } while (dec >= 10) { - resul += "X"; + resul.append("X"); dec -= 10; } while (dec >= 9) { - resul += "IX"; + resul.append("IX"); dec -= 9; } while (dec >= 5) { - resul += "V"; + resul.append("V"); dec -= 5; } while (dec >= 4) { - resul += "IV"; + resul.append("IV"); dec -= 4; } while (dec >= 1) { - resul += "I"; + resul.append("I"); dec -= 1; } - return resul; + return resul.toString(); } - // Returns a string containing the entered Roman numeral in numeral form. - public String romanToDec(String s) { - - - - int resul = 0; - int last_digit = 0; - int current_digit = 0; - - for (int i = 0; i < s.length(); i++) { - current_digit = RomanNumber.parse(s.charAt(i)); - - - //This is the tricky part. - //If the last number is smaller than the curren number, subtract the last number from the current number - //Otherwise, just add the current number. We must also skip the first number from this rule simply because - //e.g. someone enters 1799 in which case it would subtract 1 from 7 - - if (last_digit < current_digit && last_digit != 0) { - current_digit -= last_digit; - resul -= last_digit; - resul += current_digit; - last_digit = current_digit; - current_digit = 0; - } else { - last_digit = current_digit; - resul += current_digit; - current_digit = 0; - } - } - - - return String.valueOf(resul); - - - } + // Returns a string containing the entered Roman numeral in numeral form. + public String romanToDec(String s) { + + int resul = 0; + int last_digit = 0; + int current_digit = 0; + + for (int i = 0; i < s.length(); i++) { + current_digit = RomanNumber.parse(s.substring(i, i + 1)); + + //This is the tricky part. + //If the last number is smaller than the curren number, subtract the last number from the current number + //Otherwise, just add the current number. We must also skip the first number from this rule simply because + //e.g. someone enters 1799 in which case it would subtract 1 from 7 + if (last_digit < current_digit && last_digit != 0) { + current_digit -= last_digit; + resul -= last_digit; + resul += current_digit; + last_digit = current_digit; + current_digit = 0; + } else { + last_digit = current_digit; + resul += current_digit; + current_digit = 0; + } + } + return String.valueOf(resul); + } - } diff --git a/exercise3.4/RomanNumberConversionTest.java b/exercise3.4/RomanNumberConversionTest.java index 3b0f34fc..7d5da9d7 100644 --- a/exercise3.4/RomanNumberConversionTest.java +++ b/exercise3.4/RomanNumberConversionTest.java @@ -50,8 +50,7 @@ public void testDecToRoman() { String expResult = "V"; String result = RomanNumberConversion.decToRoman(dec); assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - //fail("The test case is a prototype."); + } /** @@ -65,8 +64,7 @@ public void testToArabic() { String expResult = "21"; String result = instance.romanToDec(s); assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - // fail("The test case is a prototype."); + } }