diff --git a/src/RomanNumerals.java b/src/RomanNumerals.java index 20904f0..d0243b4 100644 --- a/src/RomanNumerals.java +++ b/src/RomanNumerals.java @@ -1,8 +1,73 @@ + public class RomanNumerals { - public int convertToInteger(String romanNum) { - // To be Implemented - return 0; + 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