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
diff --git a/clean-code.iml b/clean-code-01.iml
similarity index 57%
rename from clean-code.iml
rename to clean-code-01.iml
index 3b18d94..c48ad5b 100644
--- a/clean-code.iml
+++ b/clean-code-01.iml
@@ -4,18 +4,10 @@
+
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
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;
}
}
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;
}
}
diff --git a/clean-code-challanges/src/main/java/PigLatinTranslator.java b/clean-code-challanges/src/main/java/PigLatinTranslator.java
index 602a04d..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").
@@ -15,9 +15,57 @@
*
* See http://en.wikipedia.org/wiki/Pig_latin for more details.
*/
+
public class PigLatinTranslator {
public String translate(String englishPhrase) {
- return null;
+ String[] words = englishPhrase.split(" ");
+ String pigLatinPhrase = "";
+ for (String word: words) {
+ if (pigLatinPhrase != "") {
+ pigLatinPhrase += " ";
+ }
+ pigLatinPhrase += translateWord(word);
+ }
+ return pigLatinPhrase;
+ }
+
+ public String translateWord(String word) {
+
+ // 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";
+ }
+
+ // 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.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.startsWith("th") || word.startsWith("qu") || word.startsWith("ch")) {
+ word = word.substring(2) + word.substring(0, 2) + "ay";
+ }
+
+ // 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.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";
+ }
+
+ // 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";
+ }
+
+ return word;
}
}
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