diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..00b4092 --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,468 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,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..6394b35 100644 --- a/clean-code-challanges/src/main/java/Acronym.java +++ b/clean-code-challanges/src/main/java/Acronym.java @@ -3,16 +3,36 @@ * * Techies love their TLA (Three Letter Acronyms)! * - * Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG). + * 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) { + String phrase; + Acronym(String phrase) { + this.phrase = phrase; } String get() { - return null; + String acronym = ""; + + char[] arrChar = new char[phrase.length()]; + + for (int i = 0; i < phrase.length(); i++) { + arrChar[i] = phrase.charAt(i); + } + + acronym += arrChar[0]; + + for(int i = 1; i match(List candidates) { + + ArrayList liste1 = new ArrayList(); + liste1.add("enlist"); + liste1.add("google"); + liste1.add("inlets"); + liste1.add("banana"); + + return null; } } diff --git a/clean-code-challanges/src/main/java/IsogramChecker.java b/clean-code-challanges/src/main/java/IsogramChecker.java index 00d4c74..4f1731d 100644 --- a/clean-code-challanges/src/main/java/IsogramChecker.java +++ b/clean-code-challanges/src/main/java/IsogramChecker.java @@ -13,10 +13,58 @@ * * The word isograms, however, is not an isogram, because the s repeats. */ -class IsogramChecker { +public class IsogramChecker { - boolean isIsogram(String phrase) { - throw new UnsupportedOperationException("Delete this statement and write your own implementation."); +// String phrase; +//// +// IsogramChecker(String phrase){ +// this.phrase = phrase; +// } + + public boolean isIsogram(String phrase) {//static + //throw new UnsupportedOperationException("Delete this statement and write your own implementation."); + String phrase1 = phrase.toLowerCase(); + boolean isIsogram = false; + //int hilfszahl = 0; + int counter = 0; + char derBuchstabe = ' '; + + //td lowercase phrase + //todo wenn grösser zwei, nur, wenn es eine leertaste oder ein bindestrich ist + + String phraseCopy = phrase1; + for(int i = 0; i counter) { + counter = hilfszahl; + //derBuchstabe = derBuchstabe+phrase.charAt(i); + // System.out.println("derBuchstabdfffe: " + phrase.charAt(i)); + derBuchstabe = phrase1.charAt(i); + } + } + + if(derBuchstabe=='-'&&counter>1 || (derBuchstabe==' '&&counter>1) || !(counter>1)){ + isIsogram=true; + }else{ + isIsogram = false; + } +// if(counter>1 || !(derBuchstabe=='-'&&counter>1)){//(Character.isLetter(derBuchstabe))){// Character.isDefined(derBuchstabe)=='-'){//|| (counter>1 && derBuchstabe='-')){ +// isIsogram = false; +// }else{ +// isIsogram = true; +// } + + // System.out.println("derBuchstabe: " + derBuchstabe); + // System.out.println("counter: "+counter); + + return isIsogram; } } diff --git a/clean-code-challanges/src/main/java/MainAcronym.java b/clean-code-challanges/src/main/java/MainAcronym.java new file mode 100644 index 0000000..568bd93 --- /dev/null +++ b/clean-code-challanges/src/main/java/MainAcronym.java @@ -0,0 +1,55 @@ +import java.util.ArrayList; + +/** + * @author - John Schmidt + * 19.09.2022, 00:44 + */ +public class MainAcronym { + + public static void main(String[] args) { + String phrase = "The Road _Not* Taken"; + + System.out.println(get(phrase)); + } + + + static String get(String phrase) { + String acronym = ""; + // phrase.split(" "); + + System.out.println("split: "+phrase); + + char[] arrChar = new char[phrase.length()]; + + for (int i = 0; i < phrase.length(); i++) { + arrChar[i] = phrase.charAt(i); + } + + acronym += arrChar[0]; + + //ArrayList arr = new ArrayList<>(); + String[] arr1= phrase.split(" "); + System.out.println("l: "+arr1.length); + for(int i = 0; i liste1 = new ArrayList(); + liste1.add("enlist"); + liste1.add("google"); + liste1.add("inlets"); + liste1.add("banana"); + + System.out.println(match(liste1)); + + } + + public String alphabet(List candidates){ + String alphabet = "abcdefghijklnmopqrstuvwxyz"; + + + return null; + } + + public static List match(List candidates) { + + System.out.println("In übergebener Liste enthalten: "); + for(int i = 0; i list2 = new ArrayList(); + list2.add("g"); + + + return list2; + } + +} diff --git a/clean-code-challanges/src/main/java/MainIsogramm.java b/clean-code-challanges/src/main/java/MainIsogramm.java new file mode 100644 index 0000000..2d75e5d --- /dev/null +++ b/clean-code-challanges/src/main/java/MainIsogramm.java @@ -0,0 +1,59 @@ +/** + * @author - John Schmidt + * 25.09.2022, 23:52 + */ +public class MainIsogramm { + public static void main(String[] args) { + + String phrase = "sixyearoldd"; + + System.out.println(findIsogramm(phrase)); + + } + + public static boolean findIsogramm(String phrase){ + //String word = phrase + " hello";- + String phrase1 = phrase.toLowerCase(); + System.out.println(phrase1); + boolean isIsogram = false; + //int hilfszahl = 0; + int counter = 0; + char derBuchstabe = ' '; + + String phraseCopy = phrase1; + for(int i = 0; i counter) { + counter = hilfszahl; + //derBuchstabe = derBuchstabe+phrase.charAt(i); + // System.out.println("derBuchstabdfffe: " + phrase.charAt(i)); + derBuchstabe = phrase1.charAt(i); + } + } + + if(derBuchstabe=='-'&&counter>1 || !(counter>1)){ + isIsogram=true; + }else{ + isIsogram = false; + } + +// if(counter>1|| (derBuchstabe=='-'&&counter>1)){ +// isIsogram = false; +// }else{ +// isIsogram = true; +// } + + System.out.println("derBuchstabe: " + derBuchstabe); + System.out.println("counter: "+counter); + + return isIsogram; + } + +} diff --git a/clean-code-challanges/src/main/java/PigLatinTranslator.java b/clean-code-challanges/src/main/java/PigLatinTranslator.java index 602a04d..653fa84 100644 --- a/clean-code-challanges/src/main/java/PigLatinTranslator.java +++ b/clean-code-challanges/src/main/java/PigLatinTranslator.java @@ -1,23 +1,154 @@ /** * Implement a program that translates from English to Pig Latin. - * + *

* Pig Latin is a made-up children's language that's intended to be confusing. It obeys a few simple rules (below), * 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"). + * 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"). * 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"). - * + *

* 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. */ public class PigLatinTranslator { public String translate(String englishPhrase) { - return null; + String[] arrEnglishPhraseSplit = englishPhrase.split(" "); + String pigPhrase = ""; + + for (int i = 0; i < arrEnglishPhraseSplit.length - 1; i++) { + pigPhrase += String.join("", translateWord(arrEnglishPhraseSplit[i]), " "); + } + pigPhrase += translateWord(arrEnglishPhraseSplit[arrEnglishPhraseSplit.length - 1]); + + return pigPhrase; + } + + + public String translateWord(String splitWordFromEnglishPhrase) { + String engWord = splitWordFromEnglishPhrase; + + String strConsonat = "bcdfghjklmnpqrstvwxyz"; + + String pigWord = ""; + + + if (engWord.length() == 1) { + if(findVowelFirstChar(engWord)==true){ + pigWord = engWord + "ay"; + } + else{ + pigWord = engWord; + } + } else if (engWord.length() == 2) { + System.out.println("xr: "+find_xr_yt_BeginningOfWord(engWord)); + if(findVowelFirstChar(engWord)==true || find_xr_yt_BeginningOfWord(engWord) == true ){ + pigWord = engWord + "ay"; + } + else{ + pigWord = engWord; + } + } else if(engWord.length()>=3){ + if(findVowelFirstChar(engWord)==true||find_xr_yt_BeginningOfWord(engWord)==true){ + pigWord = engWord + "ay"; + } + else{ + pigWord = engWord; + } + + if(findConsonantFirstChar(engWord)== true){ + char first = engWord.charAt(0);//engWord.substring(engWord.charAt(0),1); + char last = engWord.charAt(engWord.length()-1); + System.out.println("first: "+first); + System.out.println("last: "+last); + + pigWord = engWord.substring(1,engWord.length())+first+"ay"; + System.out.println("piggy:" + pigWord); + System.out.println("Consonant:" + findConsonantFirstChar(engWord)); + } + + } + + + return pigWord; + } + public boolean findConsonantFirstChar(String engWord){ + boolean bIsConsonantFirstChar = false; + String strConsonant = "bcdfghjklmnpqrstvwxyz"; + char charfirstCharakter = engWord.charAt(0); + for (int i = 0; i < strConsonant.length(); i++) { + if (engWord.charAt(0) == (strConsonant.charAt(i))) { + bIsConsonantFirstChar = true; + break; + } else { + bIsConsonantFirstChar = false; + } + } + return bIsConsonantFirstChar; + } + + + + + public boolean findVowelFirstChar(String engWord) { + boolean bIsFirstCharakterVowel = false; + String strVowel = "aeiou"; + char charfirstCharakter = engWord.charAt(0); + for (int i = 0; i < strVowel.length(); i++) { + if (engWord.charAt(0) == (strVowel.charAt(i))) { + bIsFirstCharakterVowel = true; + break; + } else { + bIsFirstCharakterVowel = false; + } + } + return bIsFirstCharakterVowel; + } + + + public boolean find_xr_yt_BeginningOfWord(String engWord){ + boolean bIs_xr_yt_BeginningOfWord = false; + + for(int i = 1; i " + strtranslate + " <--"); + } + + + public static String translate(String englishPhrase) { + String[] arrEnglishPhraseSplit = englishPhrase.split(" "); + String pigPhrase = ""; + + for (int i = 0; i < arrEnglishPhraseSplit.length - 1; i++) { + pigPhrase += String.join("", translateWord(arrEnglishPhraseSplit[i]), "_"); + } + pigPhrase += translateWord(arrEnglishPhraseSplit[arrEnglishPhraseSplit.length - 1]); + + return pigPhrase; + } + + public static String translateWord(String engWord) { + String pigWord = ""; + String strVowel = "aeiou"; + + + if (engWord.length() == 1) { + if(findVowelFirstChar(engWord)==true){ + pigWord = engWord + "ay"; + } + else{ + pigWord = engWord; + } + } else if (engWord.length() == 2) { + System.out.println("xr: "+find_xr_yt_BeginningOfWord(engWord)); + if(findVowelFirstChar(engWord)==true || find_xr_yt_BeginningOfWord(engWord) == true ){ + pigWord = engWord + "ay"; + } + else{ + pigWord = engWord; + } + } else if(engWord.length()>=3){ + if(findVowelFirstChar(engWord)==true||find_xr_yt_BeginningOfWord(engWord)==true){ + pigWord = engWord + "ay"; + } + else{ + pigWord = engWord; + } + + if(findConsonantFirstChar(engWord)== true){ + char first = engWord.charAt(0);//engWord.substring(engWord.charAt(0),1); + char last = engWord.charAt(engWord.length()-1); + System.out.println("first: "+first); + System.out.println("last: "+last); + + pigWord = engWord.substring(1,engWord.length())+first+"ay"; + System.out.println("piggy:" + pigWord); + System.out.println("Consonant:" + findConsonantFirstChar(engWord)); + } + + } + + + return pigWord; + } + + public static boolean findConsonantFirstChar(String engWord){ + boolean bIsConsonantFirstChar = false; + String strConsonant = "bcdfghjklmnpqrstvwxyz"; + char charfirstCharakter = engWord.charAt(0); + for (int i = 0; i < strConsonant.length(); i++) { + if (engWord.charAt(0) == (strConsonant.charAt(i))) { + bIsConsonantFirstChar = true; + break; + } else { + bIsConsonantFirstChar = false; + } + } + return bIsConsonantFirstChar; + } + + public static boolean find_xr_yt_BeginningOfWord(String engWord){ + boolean bIs_xr_yt_BeginningOfWord = false; + + for(int i = 1; i