Skip to content

Commit

Permalink
Reto mouredev#15 - Java
Browse files Browse the repository at this point in the history
  • Loading branch information
ASJordi committed Jul 21, 2023
1 parent 6c26935 commit 0054cf6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Retos/Reto #15 - AUREBESH [Fácil]/java/asjordi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.util.HashMap;
import java.util.Map;

public class Aurebesh {

public String translateToAurebesh(String sentence) {

Map<String, String> alphabetMap = createAlphabetMap();
StringBuilder res = new StringBuilder();
String[] arr = sentence.split("");

for (String s : arr) {
if (!alphabetMap.containsKey(s)) {
res.append(s);
continue;
}
res.append(alphabetMap.get(s));
}

return res.toString();

}

public String translateFromAurebesh(String sentence) {

Map<String, String> alphabetMap = createAlphabetMap();

for (Map.Entry <String, String> map: alphabetMap.entrySet()) {
sentence = sentence.replace(map.getValue(), map.getKey());
}

return sentence;

}

private static Map<String, String> createAlphabetMap(){
Map<String, String> alphabet = new HashMap<>();
alphabet.put("a", "aurek"); alphabet.put("b", "besh"); alphabet.put("c", "cresh"); alphabet.put("d", "dorn");
alphabet.put("e", "esk"); alphabet.put("f", "forn"); alphabet.put("g", "grek"); alphabet.put("h", "herf");
alphabet.put("i", "isk"); alphabet.put("j", "jenth"); alphabet.put("k", "krill"); alphabet.put("l", "leth");
alphabet.put("m", "merm"); alphabet.put("n", "nern"); alphabet.put("o", "osk"); alphabet.put("p", "peth");
alphabet.put("q", "qek"); alphabet.put("r", "resh"); alphabet.put("s", "senth"); alphabet.put("t", "trill");
alphabet.put("u", "usk"); alphabet.put("v", "vev"); alphabet.put("w", "wesk"); alphabet.put("x", "xesh");
alphabet.put("y", "yirt"); alphabet.put("z", "zerek");
return alphabet;
}

}

0 comments on commit 0054cf6

Please sign in to comment.