From 3faa6a8217a11b417ae77342f6b1dbfd23057db3 Mon Sep 17 00:00:00 2001 From: brian Date: Mon, 27 Nov 2017 10:05:44 -0500 Subject: [PATCH] Saving progress --- src/main/java/io/zipcoder/Problem1.java | 30 +++++++++++++++++++++ src/test/java/io/zipcoder/Problem1Test.java | 26 ++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/main/java/io/zipcoder/Problem1.java b/src/main/java/io/zipcoder/Problem1.java index 6cd6024..d104981 100644 --- a/src/main/java/io/zipcoder/Problem1.java +++ b/src/main/java/io/zipcoder/Problem1.java @@ -1,4 +1,34 @@ package io.zipcoder; +import java.util.HashMap; + public class Problem1 { + + public String replaceByIteration(String input) { + HashMap map = new HashMap(); + map.put("f", "7"); + map.put("s", "$"); + map.put("1", "!"); + map.put("a", "@"); + + String returnString = ""; + + for (int i = 0; i < input.length(); i++) { + String currentSubstring = input.substring(i, i + 1); + + if (currentSubstring.equals("f") || currentSubstring.equals("s") || currentSubstring.equals("1") || currentSubstring.equals("a")) { + returnString += map.get(currentSubstring); + } else { + returnString += currentSubstring; + } + } + return returnString; + } + + public String replaceByRecursion(String input) { + String returnString; + returnString = input.substring(0,1); + //returnString += replaceByRecursion(returnString); + return returnString; + } } diff --git a/src/test/java/io/zipcoder/Problem1Test.java b/src/test/java/io/zipcoder/Problem1Test.java index de82e99..d89dca5 100644 --- a/src/test/java/io/zipcoder/Problem1Test.java +++ b/src/test/java/io/zipcoder/Problem1Test.java @@ -1,4 +1,30 @@ package io.zipcoder; +import org.junit.Assert; +import org.junit.Test; + public class Problem1Test { + + @Test + public void replaceByIterationTest() { + String input = "The farmer went to the store to get 1 dollar's worth of fertilizer"; + + String actual = new Problem1().replaceByIteration(input); + + String expected = "The 7@rmer went to the $tore to get ! doll@r'$ worth o7 7ertilizer"; + + Assert.assertEquals(expected, actual); + } + + @Test + public void replaceByRecursionTest() { + String input = "The farmer went to the store to get 1 dollar's worth of fertilizer"; + + String actual = new Problem1().replaceByRecursion(input); + + String expected = "The 7@rmer went to the $tore to get ! doll@r'$ worth o7 7ertilizer"; + + Assert.assertEquals(expected, actual); + } + }