forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mouredev#4227 from ASJordi/main
Reto mouredev#15 - Java
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |