From a9de6487a5362464bdcdc2c17b1de5451088e919 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 17:35:11 +0100 Subject: [PATCH] Generalize code. From duplications we identify pattern and generalize our code. --- .../org/craftedsw/romannumerals/RomanNumeralGenerator.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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; } } -- 2.1.4