From 0cd5b8d815879e14b1ee775ac1793325c93e8a72 Mon Sep 17 00:00:00 2001 From: nadavisuals <44897257+nadavisuals@users.noreply.github.com> Date: Wed, 16 Sep 2020 23:47:05 +0200 Subject: [PATCH 1/8] Test --- clean-code-challanges/src/main/java/PigLatinTranslator.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clean-code-challanges/src/main/java/PigLatinTranslator.java b/clean-code-challanges/src/main/java/PigLatinTranslator.java index 602a04d..e2dae9d 100644 --- a/clean-code-challanges/src/main/java/PigLatinTranslator.java +++ b/clean-code-challanges/src/main/java/PigLatinTranslator.java @@ -14,10 +14,12 @@ * There are a few more rules for edge cases, and there are regional variants too. * * See http://en.wikipedia.org/wiki/Pig_latin for more details. + * Test */ public class PigLatinTranslator { public String translate(String englishPhrase) { + return null; } } From 64c2a82612cb6a6b7d483783d9b86487d6bce86b Mon Sep 17 00:00:00 2001 From: nadavisuals <44897257+nadavisuals@users.noreply.github.com> Date: Thu, 17 Sep 2020 00:21:21 +0200 Subject: [PATCH 2/8] Test 2 --- .../src/main/java/PigLatinTranslator.java | 9 ++++++++ clean-code-challanges/src/main/main.iml | 11 ++++++++++ clean-code-challanges/src/test/test.iml | 22 +++++++++++++++++++ clean-code.iml | 10 --------- 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 clean-code-challanges/src/main/main.iml create mode 100644 clean-code-challanges/src/test/test.iml diff --git a/clean-code-challanges/src/main/java/PigLatinTranslator.java b/clean-code-challanges/src/main/java/PigLatinTranslator.java index e2dae9d..9aa42e0 100644 --- a/clean-code-challanges/src/main/java/PigLatinTranslator.java +++ b/clean-code-challanges/src/main/java/PigLatinTranslator.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + /** * Implement a program that translates from English to Pig Latin. * @@ -22,4 +24,11 @@ public String translate(String englishPhrase) { return null; } + + + public static void main(String[] args) { + + } + + } diff --git a/clean-code-challanges/src/main/main.iml b/clean-code-challanges/src/main/main.iml new file mode 100644 index 0000000..908ad4f --- /dev/null +++ b/clean-code-challanges/src/main/main.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/clean-code-challanges/src/test/test.iml b/clean-code-challanges/src/test/test.iml new file mode 100644 index 0000000..bf10073 --- /dev/null +++ b/clean-code-challanges/src/test/test.iml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/clean-code.iml b/clean-code.iml index 3b18d94..c90834f 100644 --- a/clean-code.iml +++ b/clean-code.iml @@ -7,15 +7,5 @@ - - - - - - - - - - \ No newline at end of file From 63f5b3b9062eb77973b546217a35f050a399db9c Mon Sep 17 00:00:00 2001 From: nadavisuals <44897257+nadavisuals@users.noreply.github.com> Date: Sun, 20 Sep 2020 22:44:52 +0200 Subject: [PATCH 3/8] First version of working Pig Latin Translator --- clean-code.iml => clean-code-01.iml | 2 + .../src/main/java/PigLatinTranslator.java | 55 ++++++++++++++++--- 2 files changed, 49 insertions(+), 8 deletions(-) rename clean-code.iml => clean-code-01.iml (71%) diff --git a/clean-code.iml b/clean-code-01.iml similarity index 71% rename from clean-code.iml rename to clean-code-01.iml index c90834f..c48ad5b 100644 --- a/clean-code.iml +++ b/clean-code-01.iml @@ -4,8 +4,10 @@ + + \ No newline at end of file diff --git a/clean-code-challanges/src/main/java/PigLatinTranslator.java b/clean-code-challanges/src/main/java/PigLatinTranslator.java index 9aa42e0..daeda33 100644 --- a/clean-code-challanges/src/main/java/PigLatinTranslator.java +++ b/clean-code-challanges/src/main/java/PigLatinTranslator.java @@ -1,5 +1,3 @@ -import java.util.Scanner; - /** * Implement a program that translates from English to Pig Latin. * @@ -16,19 +14,60 @@ * There are a few more rules for edge cases, and there are regional variants too. * * See http://en.wikipedia.org/wiki/Pig_latin for more details. - * Test */ + public class PigLatinTranslator { public String translate(String englishPhrase) { - - return null; + String[] words = englishPhrase.split(" "); + String newStr = ""; + for (String word: words) { + if (newStr != "") { + newStr += " "; + } + newStr += translateWord(word); + } + return newStr; } + public String translateWord(String word) { - public static void main(String[] args) { - - } + // Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word. + // Please note that "xr" and "yt" at the beginning of a word make vowel sounds (e.g. "xray" -> "xrayay", "yttria" -> "yttriaay"). + if(word.indexOf("a") == 0 || word.indexOf("e") == 0 || word.indexOf("i") == 0 || word.indexOf("o") == 0 + || word.indexOf("u") == 0 || word.indexOf("xr") == 0 || word.indexOf("yt") == 0) { + return word + "ay"; + } + // Rule 3: If a word starts with a consonant sound followed by "qu", + // move it to the end of the word, and then add an "ay" sound to the end of the word (e.g. "square" -> "aresquay"). + else if(word.indexOf("qu") == 1) { + word = word.substring(3) + word.substring(0, 1) + "quay"; + } + // word starting with "sch" or "thr" or "th" or "qu" or "ch" --> take first substring and move it to the end, then add "ay" + else if(word.indexOf("sch") == 0 || word.indexOf("thr") == 0) { + word = word.substring(3) + word.substring(0, 3) + "ay"; + } + // word starting with "th" or "qu" or "ch" --> take first substring and move it to the end, then add "ay" + else if(word.indexOf("th") == 0 || word.indexOf("qu") == 0 || word.indexOf("ch") == 0) { + word = word.substring(2) + word.substring(0, 2) + "ay"; + } + // Rule 4: If a word contains a "y" after a consonant cluster or as the second letter in a two letter word + // it makes a vowel sound (e.g. "rhythm" -> "ythmrhay", "my" -> "ymay"). + else if(!(word.indexOf("a") == 0 || word.indexOf("e") == 0 || word.indexOf("i") == 0 || word.indexOf("o") == 0 || word.indexOf("u") == 0) && + !(word.indexOf("a") == 1 || word.indexOf("e") == 1 || word.indexOf("i") == 1 || word.indexOf("o") == 1 || word.indexOf("u") == 1) && + word.indexOf("y") == 2) { + word = word.substring(2) + word.substring(0, 2) + "ay"; + } + + // Rule 2: If a word begins with a consonant sound, move it to the end of the word and then add an "ay" sound to the end of the word. + // Consonant sounds can be made up of multiple consonants, a.k.a. a consonant cluster (e.g. "chair" -> "airchay"). + else if(word.substring(0, 1) != "a" || word.substring(0, 1) != "e" || word.substring(0, 1) != "i" + || word.substring(0, 1) != "o" || word.substring(0, 1) != "u") { + word = word.substring(1) + word.substring(0, 1) + "ay"; + } + + return word; + } } From 8cb728c06e8837759240309e7a496cc09496b813 Mon Sep 17 00:00:00 2001 From: nadavisuals <44897257+nadavisuals@users.noreply.github.com> Date: Fri, 25 Sep 2020 18:44:41 +0200 Subject: [PATCH 4/8] piglatin translater updated with inputs from review --- .../src/main/java/PigLatinTranslator.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/clean-code-challanges/src/main/java/PigLatinTranslator.java b/clean-code-challanges/src/main/java/PigLatinTranslator.java index daeda33..b5c738b 100644 --- a/clean-code-challanges/src/main/java/PigLatinTranslator.java +++ b/clean-code-challanges/src/main/java/PigLatinTranslator.java @@ -20,49 +20,47 @@ public class PigLatinTranslator { public String translate(String englishPhrase) { String[] words = englishPhrase.split(" "); - String newStr = ""; + String pigLatinPhrase = ""; for (String word: words) { - if (newStr != "") { - newStr += " "; + if (pigLatinPhrase != "") { + pigLatinPhrase += " "; } - newStr += translateWord(word); + pigLatinPhrase += translateWord(word); } - return newStr; + return pigLatinPhrase; } public String translateWord(String word) { - // Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word. - // Please note that "xr" and "yt" at the beginning of a word make vowel sounds (e.g. "xray" -> "xrayay", "yttria" -> "yttriaay"). - if(word.indexOf("a") == 0 || word.indexOf("e") == 0 || word.indexOf("i") == 0 || word.indexOf("o") == 0 - || word.indexOf("u") == 0 || word.indexOf("xr") == 0 || word.indexOf("yt") == 0) { + // If word begins with a vowel, add an "ay" to the end of the word + if(word.startsWith("a") || word.startsWith("e") || word.startsWith("i") || word.startsWith("o") + || word.startsWith("u") || word.startsWith("xr") || word.startsWith("yt")) { return word + "ay"; } - // Rule 3: If a word starts with a consonant sound followed by "qu", - // move it to the end of the word, and then add an "ay" sound to the end of the word (e.g. "square" -> "aresquay"). + // If word starts with a consonant followed by "qu", + // move it to the end of the word, and then add an "ay" sound to the end of the word (e.g. "square" -> "aresquay") else if(word.indexOf("qu") == 1) { word = word.substring(3) + word.substring(0, 1) + "quay"; } // word starting with "sch" or "thr" or "th" or "qu" or "ch" --> take first substring and move it to the end, then add "ay" - else if(word.indexOf("sch") == 0 || word.indexOf("thr") == 0) { + else if(word.startsWith("sch") || word.startsWith("thr")) { word = word.substring(3) + word.substring(0, 3) + "ay"; } // word starting with "th" or "qu" or "ch" --> take first substring and move it to the end, then add "ay" - else if(word.indexOf("th") == 0 || word.indexOf("qu") == 0 || word.indexOf("ch") == 0) { + else if(word.startsWith("th") || word.startsWith("qu") || word.startsWith("ch")) { word = word.substring(2) + word.substring(0, 2) + "ay"; } - // Rule 4: If a word contains a "y" after a consonant cluster or as the second letter in a two letter word + // If word contains a "y" after a consonant cluster or as the second letter in a two letter word // it makes a vowel sound (e.g. "rhythm" -> "ythmrhay", "my" -> "ymay"). - else if(!(word.indexOf("a") == 0 || word.indexOf("e") == 0 || word.indexOf("i") == 0 || word.indexOf("o") == 0 || word.indexOf("u") == 0) && - !(word.indexOf("a") == 1 || word.indexOf("e") == 1 || word.indexOf("i") == 1 || word.indexOf("o") == 1 || word.indexOf("u") == 1) && + else if(!(word.startsWith("a") || word.startsWith("e") || word.startsWith("i") || word.startsWith("o") || word.startsWith("u")) && + !(word.startsWith("a") || word.startsWith("e") || word.startsWith("i") || word.startsWith("o") || word.startsWith("u")) && word.indexOf("y") == 2) { word = word.substring(2) + word.substring(0, 2) + "ay"; } - // Rule 2: If a word begins with a consonant sound, move it to the end of the word and then add an "ay" sound to the end of the word. - // Consonant sounds can be made up of multiple consonants, a.k.a. a consonant cluster (e.g. "chair" -> "airchay"). + // If word begins with consonant, move it to the end of the word and then add "ay" to the end of the word else if(word.substring(0, 1) != "a" || word.substring(0, 1) != "e" || word.substring(0, 1) != "i" || word.substring(0, 1) != "o" || word.substring(0, 1) != "u") { word = word.substring(1) + word.substring(0, 1) + "ay"; From 11e5aba5f73027fc371a9fd934dcbc7590c65814 Mon Sep 17 00:00:00 2001 From: nadavisuals <44897257+nadavisuals@users.noreply.github.com> Date: Fri, 25 Sep 2020 18:47:42 +0200 Subject: [PATCH 5/8] piglatin translater updated with inputs from review --- .idea/$PRODUCT_WORKSPACE_FILE$ | 19 +++++++++++++++++++ .idea/checkstyle-idea.xml | 15 --------------- .idea/codeStyleSettings.xml | 9 --------- .idea/jarRepositories.xml | 20 -------------------- .idea/kotlinc.xml | 7 ------- .idea/misc.xml | 6 +----- .idea/modules.xml | 4 +++- .idea/modules/clean-code-challanges.iml | 2 -- .idea/vcs.xml | 2 +- 9 files changed, 24 insertions(+), 60 deletions(-) create mode 100644 .idea/$PRODUCT_WORKSPACE_FILE$ delete mode 100644 .idea/checkstyle-idea.xml delete mode 100644 .idea/codeStyleSettings.xml delete mode 100644 .idea/jarRepositories.xml delete mode 100644 .idea/kotlinc.xml delete mode 100644 .idea/modules/clean-code-challanges.iml diff --git a/.idea/$PRODUCT_WORKSPACE_FILE$ b/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 0000000..3733e0d --- /dev/null +++ b/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,19 @@ + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml deleted file mode 100644 index ab65fd9..0000000 --- a/.idea/checkstyle-idea.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml deleted file mode 100644 index 5555dd2..0000000 --- a/.idea/codeStyleSettings.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index fdc392f..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 1c24f9a..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index a2de11b..e208459 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,10 +1,6 @@ - - - - - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index ee6671a..aa18f50 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,9 @@ - + + + \ No newline at end of file diff --git a/.idea/modules/clean-code-challanges.iml b/.idea/modules/clean-code-challanges.iml deleted file mode 100644 index c492207..0000000 --- a/.idea/modules/clean-code-challanges.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file From 03352e2254f1af0af5c70d95da11e1ffd7649d7b Mon Sep 17 00:00:00 2001 From: nadavisuals <44897257+nadavisuals@users.noreply.github.com> Date: Sat, 3 Oct 2020 09:54:56 +0200 Subject: [PATCH 6/8] Testing.. --- clean-code-challanges/src/main/java/PigLatinTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean-code-challanges/src/main/java/PigLatinTranslator.java b/clean-code-challanges/src/main/java/PigLatinTranslator.java index b5c738b..33c0c4e 100644 --- a/clean-code-challanges/src/main/java/PigLatinTranslator.java +++ b/clean-code-challanges/src/main/java/PigLatinTranslator.java @@ -5,7 +5,7 @@ * but when it's spoken quickly it's really difficult for non-children (and non-native speakers) to understand. * * Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word. - * Please note that "xr" and "yt" at the beginning of a word make vowel sounds (e.g. "xray" -> "xrayay", "yttria" -> "yttriaay"). + * Please note that "xr" and "yt" at the beginning of a word make vowel sounds (e.g. "xray" -> "xrayay", "yttria" -> "yttriaay"). * Rule 2: If a word begins with a consonant sound, move it to the end of the word and then add an "ay" sound to the end of the word. * Consonant sounds can be made up of multiple consonants, a.k.a. a consonant cluster (e.g. "chair" -> "airchay"). * Rule 3: If a word starts with a consonant sound followed by "qu", move it to the end of the word, and then add an "ay" sound to the end of the word (e.g. "square" -> "aresquay"). From 57fdaeec6bcb0d11de7b9136cae01ba3f1488bef Mon Sep 17 00:00:00 2001 From: nadavisuals <44897257+nadavisuals@users.noreply.github.com> Date: Sun, 4 Oct 2020 19:51:32 +0200 Subject: [PATCH 7/8] Acronym Generator first version. 8 of 9 tests passed. --- .../src/main/java/Acronym.java | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/clean-code-challanges/src/main/java/Acronym.java b/clean-code-challanges/src/main/java/Acronym.java index 5e00939..13c461e 100644 --- a/clean-code-challanges/src/main/java/Acronym.java +++ b/clean-code-challanges/src/main/java/Acronym.java @@ -5,14 +5,52 @@ * * Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG). */ + class Acronym { - Acronym(String phrase) { + private String phrase; + Acronym(String phrase) { + this.phrase = phrase; } + + + String get() { - return null; + lineDeleter(phrase); + +// if(phrase.contains(" - ")) { +// phrase = phrase.replace("-"," "); +// return phrase; +// } + + // PhraseContainsLine AND leftAndRightIsWhiteSpace + + // phrase = phrase.replace(" - "," "); + + String[] words = phrase.split(" "); + StringBuilder acronymPhrase = new StringBuilder(); + for (String word : words) { + if (word.startsWith("_") && word.endsWith("_")) { + String acronymMinusUnderline = word.substring(1, word.length() - 1); + acronymPhrase.append(acronymMinusUnderline.substring(0, 1).toUpperCase()); + + } else if (word.contains("-")) { + word.replace(word, "\\s"); + + } else { + acronymPhrase.append(word.substring(0, 1).toUpperCase()); + } + } + return acronymPhrase.toString(); + } + + public String lineDeleter(String phrase){ + String result = phrase = phrase.replace(" - "," "); + result = phrase.replaceAll("_", ""); + result = phrase.replaceAll("-", " "); +return result; } } From 3ea6939a891b4e124e09405f6f55ecf5c4d6b9d9 Mon Sep 17 00:00:00 2001 From: nadavisuals <44897257+nadavisuals@users.noreply.github.com> Date: Wed, 14 Oct 2020 21:17:05 +0200 Subject: [PATCH 8/8] Implemented a solution for the anagram challange --- .../src/main/java/Anagram.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/clean-code-challanges/src/main/java/Anagram.java b/clean-code-challanges/src/main/java/Anagram.java index 9930cd0..796fbc5 100644 --- a/clean-code-challanges/src/main/java/Anagram.java +++ b/clean-code-challanges/src/main/java/Anagram.java @@ -1,3 +1,5 @@ +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -7,11 +9,30 @@ */ public class Anagram { + private final String word; + public Anagram(String word) { + this.word = word; + } + String sortLetters(String word) { + char[] letterArray = word.toLowerCase().toCharArray(); + Arrays.sort(letterArray); + String sorted = new String(letterArray); + return sorted; } public List match(List candidates) { - return null; + List matchingWords = new ArrayList(); + + String sortedWord = sortLetters(this.word); + + for (String word : candidates) { + String sortedWordToMatch = sortLetters(word); + if (sortedWord.equals(sortedWordToMatch) && !this.word.toLowerCase().equals(word.toLowerCase())) { + matchingWords.add(word); + } + } + return matchingWords; } }