diff --git a/Answers/40230112126/.idea/.gitignore b/Answers/40230112126/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Answers/40230112126/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Answers/40230112126/.idea/.name b/Answers/40230112126/.idea/.name new file mode 100644 index 0000000..296aa65 --- /dev/null +++ b/Answers/40230112126/.idea/.name @@ -0,0 +1 @@ +Advanced.java \ No newline at end of file diff --git a/Answers/40230112126/.idea/compiler.xml b/Answers/40230112126/.idea/compiler.xml new file mode 100644 index 0000000..69cd7fc --- /dev/null +++ b/Answers/40230112126/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112126/.idea/dbnavigator.xml b/Answers/40230112126/.idea/dbnavigator.xml new file mode 100644 index 0000000..ac5f94f --- /dev/null +++ b/Answers/40230112126/.idea/dbnavigator.xml @@ -0,0 +1,406 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112126/.idea/encodings.xml b/Answers/40230112126/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Answers/40230112126/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Answers/40230112126/.idea/jarRepositories.xml b/Answers/40230112126/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/Answers/40230112126/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112126/.idea/libraries/junit_jupiter.xml b/Answers/40230112126/.idea/libraries/junit_jupiter.xml new file mode 100644 index 0000000..965272a --- /dev/null +++ b/Answers/40230112126/.idea/libraries/junit_jupiter.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112126/.idea/misc.xml b/Answers/40230112126/.idea/misc.xml new file mode 100644 index 0000000..e2044d1 --- /dev/null +++ b/Answers/40230112126/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112126/.idea/uiDesigner.xml b/Answers/40230112126/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/Answers/40230112126/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112126/.idea/vcs.xml b/Answers/40230112126/.idea/vcs.xml new file mode 100644 index 0000000..64713b8 --- /dev/null +++ b/Answers/40230112126/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Answers/40230112126/pom.xml b/Answers/40230112126/pom.xml new file mode 100644 index 0000000..6803a74 --- /dev/null +++ b/Answers/40230112126/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/40230112126/src/main/java/Advanced.java b/Answers/40230112126/src/main/java/Advanced.java new file mode 100644 index 0000000..5ea8f5c --- /dev/null +++ b/Answers/40230112126/src/main/java/Advanced.java @@ -0,0 +1,63 @@ +import java.util.Objects; + +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){ + sentence = sentence.replace(word, newWord); + 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.toLowerCase(); + String firstLetterName = firstName.substring(0,1); //extracting the first word. + firstName = firstLetterName.toUpperCase() + firstName.substring(1); + + // first name is uppercase first word + rest of the word. + + boolean check = lastName.isBlank(); + if (check==false) { + lastName = lastName.toLowerCase(); + String firstLetterLastName = lastName.substring(0, 1); + lastName = firstLetterLastName.toUpperCase() + lastName.substring(1); + + String fullName = firstName + " " + lastName; + return fullName; + } + else + return firstName; + } + + /** + * 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) { + String answer=""; + for (int i=0 ; i words.length) { + String errorPrompt = "Number = " + number + "is out Of Bound"; + return errorPrompt; + } else { + return words[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 odd=0; + int even=0; + + for(int i=0; i < number.length(); i++) { + if(number.charAt(i) % 2 == 1) + odd++; + else{ + even++; + } + } + + if (searchForEven == true) + return even; + else { + return odd; + } + } + + /** + * @param wordA --> first word + * @param wordB --> second word + * @return The word that is first in alphabet column + */ + public String firstWord(String wordA, String wordB) { + int result = wordA.compareToIgnoreCase(wordB); + if (result > 0) + return wordB; + else { + if (result < 0) + return wordA; + else { + return "identical words!"; + } + } + } +} diff --git a/Answers/40230112126/src/test/java/StringTest.java b/Answers/40230112126/src/test/java/StringTest.java new file mode 100644 index 0000000..3e13bf7 --- /dev/null +++ b/Answers/40230112126/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("Tem", warmup.wordFinder("Happy New Term", 1)); + 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/40230112126/target/classes/Advanced.class b/Answers/40230112126/target/classes/Advanced.class new file mode 100644 index 0000000..8472742 Binary files /dev/null and b/Answers/40230112126/target/classes/Advanced.class differ diff --git a/Answers/40230112126/target/classes/Warmup.class b/Answers/40230112126/target/classes/Warmup.class new file mode 100644 index 0000000..8b98a9f Binary files /dev/null and b/Answers/40230112126/target/classes/Warmup.class differ diff --git a/Answers/40230112126/target/test-classes/StringTest.class b/Answers/40230112126/target/test-classes/StringTest.class new file mode 100644 index 0000000..9836ff1 Binary files /dev/null and b/Answers/40230112126/target/test-classes/StringTest.class differ