diff --git a/Answers/40230112037/.idea/.gitignore b/Answers/40230112037/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Answers/40230112037/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Answers/40230112037/.idea/compiler.xml b/Answers/40230112037/.idea/compiler.xml new file mode 100644 index 0000000..69cd7fc --- /dev/null +++ b/Answers/40230112037/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/.idea/dbnavigator.xml b/Answers/40230112037/.idea/dbnavigator.xml new file mode 100644 index 0000000..ac5f94f --- /dev/null +++ b/Answers/40230112037/.idea/dbnavigator.xml @@ -0,0 +1,406 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/.idea/encodings.xml b/Answers/40230112037/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Answers/40230112037/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/.idea/jarRepositories.xml b/Answers/40230112037/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/Answers/40230112037/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/.idea/libraries/junit_jupiter.xml b/Answers/40230112037/.idea/libraries/junit_jupiter.xml new file mode 100644 index 0000000..965272a --- /dev/null +++ b/Answers/40230112037/.idea/libraries/junit_jupiter.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/.idea/misc.xml b/Answers/40230112037/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/Answers/40230112037/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/.idea/uiDesigner.xml b/Answers/40230112037/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/Answers/40230112037/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/.idea/vcs.xml b/Answers/40230112037/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/Answers/40230112037/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/40230112037/pom.xml b/Answers/40230112037/pom.xml new file mode 100644 index 0000000..6803a74 --- /dev/null +++ b/Answers/40230112037/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + org.example + StringMaster + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + + + + org.junit + junit-bom + 5.8.2 + pom + import + + + + + + + org.junit.jupiter + junit-jupiter + test + + + + \ No newline at end of file diff --git a/Answers/40230112037/src/main/java/Advanced.java b/Answers/40230112037/src/main/java/Advanced.java new file mode 100644 index 0000000..dd21345 --- /dev/null +++ b/Answers/40230112037/src/main/java/Advanced.java @@ -0,0 +1,55 @@ +public class Advanced { + + /** + * Goal : Changing a Sentence Content + + * In this function, you have a sentence, a word & a newWord as Entry + * You have to search the sentence to find the word that you were given as input and change it with the newWord + + */ + public String wordCensor(String sentence, String word, String newWord) { + int index = sentence.indexOf(word); + while (index >= 0) { + sentence = String.valueOf(sentence.toCharArray(), 0, index) + newWord + String.valueOf(sentence.toCharArray(), index + word.length(), sentence.length() - index - word.length()); + index = sentence.indexOf(word, index - word.length() + newWord.length() + 1); + } + return sentence; + } + + /** + * In this function You have a firstName and a lastName as Entry and you have to normalize them as a fullName + * @param firstName is a first name with irregular letters (example : hARry) + * @param lastName is a last name with irregular letters (example : pOtTeR) + * @return fullName is a normal full name that just the first letter of firstName & lastName is Capitalized (example : Harry Potter) + */ + public String normalizingName(String firstName, String lastName) { + firstName = firstName.substring(0, 1).toUpperCase() + firstName.substring(1).toLowerCase(); + lastName = lastName.substring(0, 1).toUpperCase() + lastName.substring(1).toLowerCase(); + if (lastName.isBlank()) + return firstName; + else if (firstName.isBlank()) + return lastName; + return firstName + " " + lastName; + } + + /** + * Removing repeated letter in a word + * @param word This input could have Consecutive repeated letters or not + * @return if word contains Consecutive repeated letters, one of the repeated letters should be omitted + */ + public String doubleChar(String word) { + if (word.isEmpty()) return ""; + char[] newWord = new char[word.length()]; + newWord[0] = word.charAt(0); + int length = 1; + char[] wordChars = word.toCharArray(); + for (int i = 1; i < wordChars.length; i++) { + if (wordChars[i] != newWord[length - 1]) { + newWord[length] = wordChars[i]; + length++; + } + } + return String.valueOf(newWord, 0, length); + } +} + diff --git a/Answers/40230112037/src/main/java/Warmup.java b/Answers/40230112037/src/main/java/Warmup.java new file mode 100644 index 0000000..e89596a --- /dev/null +++ b/Answers/40230112037/src/main/java/Warmup.java @@ -0,0 +1,42 @@ +public class Warmup { + + /** + * Goal : Simple Introduction To Strings + * In the first function, your inputs are a number and a sentence + * @return is the number th word of the sentence + */ + public String wordFinder(String sentence, int number) { + String[] splited_string = sentence.split(" "); + if (number < 1 | number > splited_string.length) return "Number = " + number + " is out Of Bound"; + return splited_string[number - 1]; + } + + /** + * Goal : Basic introduction to Strings & using foreach + * @param number is in String type + * @param searchForEven is a boolean entry + * @return if searchForEven is true ? return the number of even numbers : return the number of odd numbers + */ + public int oddEvenCounter(String number, boolean searchForEven) { + int count = 0; + for (Character i : number.toCharArray()) { + int numeric_i = Character.getNumericValue(i); + if (numeric_i >= 0 & numeric_i < 10) if ((Character.getNumericValue(i) % 2 == 0) == searchForEven) count++; + } + return count; + } + + /** + * @param wordA --> first word + * @param wordB --> second word + * @return The word that is first in alphabet column + */ + public String firstWord(String wordA, String wordB) { + for (int i = 0; i < wordA.length(); i++) { + if (wordA.charAt(i) == wordB.charAt(i)) continue; + if (wordA.charAt(i) > wordB.charAt(i)) return wordB; + else return wordA; + } + return wordA; + } +} diff --git a/Answers/40230112037/src/test/java/StringTest.java b/Answers/40230112037/src/test/java/StringTest.java new file mode 100644 index 0000000..cca58b3 --- /dev/null +++ b/Answers/40230112037/src/test/java/StringTest.java @@ -0,0 +1,41 @@ +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class StringTest { + + Warmup warmup = new Warmup(); + Advanced advanced = new Advanced(); + @Test + public void wordFinder_test(){ + assertEquals("Term", warmup.wordFinder("Happy New Term", 3)); + assertEquals("Number = 4 is out Of Bound", warmup.wordFinder("Hello From Java", 4)); + } + @Test + public void oddEvenCounter_test(){ + assertEquals(2, warmup.oddEvenCounter("43512", true)); + assertEquals(0, warmup.oddEvenCounter("00000", false)); + assertEquals(4, warmup.oddEvenCounter("1111", false)); + } + @Test + public void firstWord_test(){ + assertEquals("Fred", warmup.firstWord("George", "Fred")); + assertEquals("Harrold", warmup.firstWord("Harry", "Harrold")); + assertEquals("Ali", warmup.firstWord("Ali", "Alson")); + assertEquals(" ", warmup.firstWord(" ", "Albus")); + } + @Test + public void wordCensor_test(){ + assertEquals("We should stop He Who Must Not Be Named", advanced.wordCensor("We should stop Voldemort", "Voldemort", "He Who Must Not Be Named")); + assertEquals("I'm Coding Java", advanced.wordCensor("I'm Coding cpp", "cpp", "Java")); + } + @Test + public void normalizingName_test(){ + assertEquals("Ron Weasley", advanced.normalizingName("rOn", "weASlEy")); + assertEquals("Hogwart", advanced.normalizingName("hoGWart", " ")); + } + @Test + public void doubleChar_test(){ + assertEquals("Hary poter", advanced.doubleChar("Harry potter")); + assertEquals("Hary", advanced.doubleChar("Harrrry")); + } +} diff --git a/Answers/40230112037/target/classes/Advanced.class b/Answers/40230112037/target/classes/Advanced.class new file mode 100644 index 0000000..b9f3974 Binary files /dev/null and b/Answers/40230112037/target/classes/Advanced.class differ diff --git a/Answers/40230112037/target/classes/Warmup.class b/Answers/40230112037/target/classes/Warmup.class new file mode 100644 index 0000000..625725a Binary files /dev/null and b/Answers/40230112037/target/classes/Warmup.class differ diff --git a/Answers/40230112037/target/test-classes/StringTest.class b/Answers/40230112037/target/test-classes/StringTest.class new file mode 100644 index 0000000..d223547 Binary files /dev/null and b/Answers/40230112037/target/test-classes/StringTest.class differ