From e915a0bcbeb5883d278f475fc6aa6ad6a37b701c Mon Sep 17 00:00:00 2001 From: amyaim Date: Mon, 27 Nov 2017 10:05:29 -0500 Subject: [PATCH 1/2] sad couldnt figure it out. but surely will get better --- src/main/java/io/zipcoder/Problem1.java | 20 ++++++++++++++++++++ src/test/java/io/zipcoder/Problem1Test.java | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/java/io/zipcoder/Problem1.java b/src/main/java/io/zipcoder/Problem1.java index 6cd6024..bde25b2 100644 --- a/src/main/java/io/zipcoder/Problem1.java +++ b/src/main/java/io/zipcoder/Problem1.java @@ -1,4 +1,24 @@ package io.zipcoder; +import javax.swing.text.html.HTMLDocument; +import java.util.*; + public class Problem1 { + + public void replaceKey(Map stringMap) { + + + stringMap = new HashMap(); + Set keyValue = stringMap.keySet(); + Map replaced = new HashMap(); + + boolean iterator = stringMap.containsKey(keyValue); + while (iterator) { + + replaced.put(keyValue, stringMap.values()) + } + } + } } + + diff --git a/src/test/java/io/zipcoder/Problem1Test.java b/src/test/java/io/zipcoder/Problem1Test.java index de82e99..1b54736 100644 --- a/src/test/java/io/zipcoder/Problem1Test.java +++ b/src/test/java/io/zipcoder/Problem1Test.java @@ -1,4 +1,14 @@ package io.zipcoder; +import org.junit.Test; + public class Problem1Test { + + Problem1 problem1 = new Problem1(); + @Test + public void replaceKey() throws Exception { + + + + } } From 235225927df7ca492b2d2fb92f304465505195ec Mon Sep 17 00:00:00 2001 From: amyaim Date: Thu, 30 Nov 2017 21:37:15 -0500 Subject: [PATCH 2/2] done --- src/main/java/io/zipcoder/Problem1.java | 33 ++++++++++++++++----- src/test/java/io/zipcoder/Problem1Test.java | 8 +++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/zipcoder/Problem1.java b/src/main/java/io/zipcoder/Problem1.java index bde25b2..be4f9f3 100644 --- a/src/main/java/io/zipcoder/Problem1.java +++ b/src/main/java/io/zipcoder/Problem1.java @@ -4,21 +4,38 @@ import java.util.*; public class Problem1 { + public String toreplaceChar(String input) { - public void replaceKey(Map stringMap) { + String input2 = input.toLowerCase(); + HashMap toReplace = new HashMap(); + toReplace.put('f' , '7'); + toReplace.put('s' , '$'); + toReplace.put('1' , '!'); + toReplace.put('a' , '@'); - stringMap = new HashMap(); - Set keyValue = stringMap.keySet(); - Map replaced = new HashMap(); + char[] inputArray = input.toCharArray(); - boolean iterator = stringMap.containsKey(keyValue); - while (iterator) { - replaced.put(keyValue, stringMap.values()) - } + 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 1b54736..7640f42 100644 --- a/src/test/java/io/zipcoder/Problem1Test.java +++ b/src/test/java/io/zipcoder/Problem1Test.java @@ -1,14 +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); } }