Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/main/java/io/zipcoder/Problem1.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
package io.zipcoder;

import java.util.HashMap;

public class Problem1 {

public String replaceByIteration(String input) {
HashMap<String, String> map = new HashMap<String, String>();
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;
}
}
26 changes: 26 additions & 0 deletions src/test/java/io/zipcoder/Problem1Test.java
Original file line number Diff line number Diff line change
@@ -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);
}

}