diff --git a/src/main/java/io/zipcoder/Problem1.java b/src/main/java/io/zipcoder/Problem1.java index 6cd6024..be4f9f3 100644 --- a/src/main/java/io/zipcoder/Problem1.java +++ b/src/main/java/io/zipcoder/Problem1.java @@ -1,4 +1,41 @@ package io.zipcoder; +import javax.swing.text.html.HTMLDocument; +import java.util.*; + public class Problem1 { + public String toreplaceChar(String input) { + + String input2 = input.toLowerCase(); + + HashMap toReplace = new HashMap(); + toReplace.put('f' , '7'); + toReplace.put('s' , '$'); + toReplace.put('1' , '!'); + toReplace.put('a' , '@'); + + char[] inputArray = input.toCharArray(); + + + for (int i = 0; i < inputArray.length; i++) { + + if (toReplace.containsKey(input.toLowerCase().charAt(i))) + inputArray[i] = toReplace.get(input2.charAt(i)); + } + + return new String(inputArray); + } } + + + + + + + + + + + + + diff --git a/src/test/java/io/zipcoder/Problem1Test.java b/src/test/java/io/zipcoder/Problem1Test.java index de82e99..7640f42 100644 --- a/src/test/java/io/zipcoder/Problem1Test.java +++ b/src/test/java/io/zipcoder/Problem1Test.java @@ -1,4 +1,22 @@ package io.zipcoder; +import org.junit.Assert; +import org.junit.Test; + + public class Problem1Test { + + + Problem1 problem1 = new Problem1(); + @Test + public void replaceKey() throws Exception { + + + String expected = "The 7@rmer went to the $tore to get ! doll@r’$ worth o7 7ertilizer"; + + String actual = problem1.toreplaceChar("The Farmer went to the store to get 1 dollar’s worth of fertilizer"); + + Assert.assertEquals(expected, actual); + + } }