From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 16:35:11 +0000 (+0100) Subject: Generalize code. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=a9de6487a5362464bdcdc2c17b1de5451088e919;p=JavaForFun Generalize code. From duplications we identify pattern and generalize our code. --- diff --git a/TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java b/TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java index 3409176..5b53491 100644 --- a/TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java +++ b/TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java @@ -3,13 +3,12 @@ package org.craftedsw.romannumerals; public class RomanNumeralGenerator { public static String romanFor(int decimal) { - if (decimal == 3) { - return "III"; + String roman = ""; + for (int i = 0; i < decimal; i++) { + roman += "I"; } - if (decimal == 2) { - return "II"; - } - return "I"; + + return roman; } }