Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loesung Anagram Dani #23

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
19 changes: 19 additions & 0 deletions .idea/$PRODUCT_WORKSPACE_FILE$

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions .idea/checkstyle-idea.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/codeStyleSettings.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/jarRepositories.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/kotlinc.xml

This file was deleted.

6 changes: 1 addition & 5 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions .idea/modules/clean-code-challanges.iml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions clean-code.iml → clean-code-01.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/clean-code-challanges/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/junit-4.12.jar!/" />
<root url="jar://$MODULE_DIR$/lib/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="gradle-wrapper" level="project" />
</component>
</module>
42 changes: 40 additions & 2 deletions clean-code-challanges/src/main/java/Acronym.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
23 changes: 22 additions & 1 deletion clean-code-challanges/src/main/java/Anagram.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -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<String> match(List<String> candidates) {
return null;
List<String> matchingWords = new ArrayList<String>();

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;
}
}
52 changes: 50 additions & 2 deletions clean-code-challanges/src/main/java/PigLatinTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand All @@ -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;
}
}
11 changes: 11 additions & 0 deletions clean-code-challanges/src/main/main.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
22 changes: 22 additions & 0 deletions clean-code-challanges/src/test/test.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module" module-name="main" scope="TEST" />
</component>
</module>