From 02c5d713b958887780f224902c775270952f5b25 Mon Sep 17 00:00:00 2001 From: mikkoyli Date: Fri, 30 Sep 2016 16:53:31 +0300 Subject: [PATCH 1/2] Project finished --- src/RomanNumerals.java | 52 +++++++++++++++++++++++++++++++-- tests/TestRomanNumerals.java | 56 ++++++++++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 5 deletions(-) diff --git a/src/RomanNumerals.java b/src/RomanNumerals.java index 20904f0..86e224f 100644 --- a/src/RomanNumerals.java +++ b/src/RomanNumerals.java @@ -1,8 +1,54 @@ + public class RomanNumerals { - public int convertToInteger(String romanNum) { - // To be Implemented - return 0; + public int convertToInteger(String romanNum) { + + int length=romanNum.length(); + int i=0; + int number = 0; + while(i Date: Fri, 7 Oct 2016 15:29:37 +0300 Subject: [PATCH 2/2] Project finished --- src/RomanNumerals.java | 25 +++++++- src/RomanNumeralsException.java | 7 +++ tests/TestRomanNumerals.java | 106 +++++++++++++++++++++++++++++--- 3 files changed, 126 insertions(+), 12 deletions(-) create mode 100644 src/RomanNumeralsException.java diff --git a/src/RomanNumerals.java b/src/RomanNumerals.java index 86e224f..d0243b4 100644 --- a/src/RomanNumerals.java +++ b/src/RomanNumerals.java @@ -1,16 +1,35 @@ public class RomanNumerals { - public int convertToInteger(String romanNum) { + public int convertToInteger(String romanNum) throws RomanNumeralsException { int length=romanNum.length(); int i=0; int number = 0; + + if (romanNum.indexOf("IIII") >= 0) + throw new RomanNumeralsException("More than three I's in row is not accepted."); + else if (romanNum.indexOf("XXXX") >= 0) + throw new RomanNumeralsException("More than three X's in row is not accepted."); + else if (romanNum.indexOf("CCCC") >= 0) + throw new RomanNumeralsException("More than three C's in row is not accepted."); + else if (romanNum.indexOf("MMMM") >= 0) + throw new RomanNumeralsException("More than three M's in row is not accepted."); + + if (romanNum.indexOf("VV") >= 0) + throw new RomanNumeralsException("More than two V's in row is not accepted."); + else if (romanNum.indexOf("LL") >= 0) + throw new RomanNumeralsException("More than two L's in row is not accepted."); + else if (romanNum.indexOf("DD") >= 0) + throw new RomanNumeralsException("More than two D's in row is not accepted."); + + // todo: two or more smaller before big results exception + while(i