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
26 changes: 26 additions & 0 deletions src/main/java/io/zipcoder/Problem1.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
package io.zipcoder;

import java.util.HashMap;

public class Problem1 {

private HashMap <Character, Character> characterMap = new HashMap<Character, Character>();

public Problem1() {
characterMap.put('f', '7');
characterMap.put('s', '$');
characterMap.put('1', '!');
characterMap.put('a', '@');
}

public String replaceCharacters(String stringToReplace){

char[] charArray = stringToReplace.toCharArray();

for (int i = 0; i < charArray.length; i++){
char charToReplace = charArray[i];
if (characterMap.containsKey(Character.toLowerCase(charToReplace))){
charArray[i] = characterMap.get(Character.toLowerCase(charToReplace));
}
}

return new String(charArray);
}

}
21 changes: 21 additions & 0 deletions src/test/java/io/zipcoder/Problem1Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class Problem1Test {

private Problem1 problem1;
private String stringToTest;

@Before
public void setUp(){
problem1 = new Problem1();
stringToTest = "The Farmer went to the store to get 1 dollar's worth of fertilizer";
}

@Test
public void replaceCharactersTest(){
String expected = "The 7@rmer went to the $tore to get ! doll@r'$ worth o7 7ertilizer";
String actual = problem1.replaceCharacters(stringToTest);
Assert.assertEquals(expected, actual);

}
}