diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..dc5daaf Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/StringMaster.iml b/.idea/StringMaster.iml new file mode 100644 index 0000000..6054576 --- /dev/null +++ b/.idea/StringMaster.iml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..69cd7fc --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..9cd9d7e --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e3e8393 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f26cac5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.DS_Store b/Answers/40230112089/.DS_Store new file mode 100644 index 0000000..24070f3 Binary files /dev/null and b/Answers/40230112089/.DS_Store differ diff --git a/Answers/40230112089/.idea/.gitignore b/Answers/40230112089/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Answers/40230112089/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Answers/40230112089/.idea/compiler.xml b/Answers/40230112089/.idea/compiler.xml new file mode 100644 index 0000000..69cd7fc --- /dev/null +++ b/Answers/40230112089/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.idea/dbnavigator.xml b/Answers/40230112089/.idea/dbnavigator.xml new file mode 100644 index 0000000..ac5f94f --- /dev/null +++ b/Answers/40230112089/.idea/dbnavigator.xml @@ -0,0 +1,406 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.idea/encodings.xml b/Answers/40230112089/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Answers/40230112089/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.idea/jarRepositories.xml b/Answers/40230112089/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/Answers/40230112089/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.idea/libraries/junit_jupiter.xml b/Answers/40230112089/.idea/libraries/junit_jupiter.xml new file mode 100644 index 0000000..965272a --- /dev/null +++ b/Answers/40230112089/.idea/libraries/junit_jupiter.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.idea/misc.xml b/Answers/40230112089/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/Answers/40230112089/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/.idea/uiDesigner.xml b/Answers/40230112089/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/Answers/40230112089/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/40230112089/pom.xml b/Answers/40230112089/pom.xml new file mode 100644 index 0000000..6803a74 --- /dev/null +++ b/Answers/40230112089/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/40230112089/src/.DS_Store b/Answers/40230112089/src/.DS_Store new file mode 100644 index 0000000..cbe4971 Binary files /dev/null and b/Answers/40230112089/src/.DS_Store differ diff --git a/Answers/40230112089/src/main/.DS_Store b/Answers/40230112089/src/main/.DS_Store new file mode 100644 index 0000000..1cf17f4 Binary files /dev/null and b/Answers/40230112089/src/main/.DS_Store differ diff --git a/Answers/40230112089/src/main/java/Advanced.java b/Answers/40230112089/src/main/java/Advanced.java new file mode 100644 index 0000000..4c195e5 --- /dev/null +++ b/Answers/40230112089/src/main/java/Advanced.java @@ -0,0 +1,70 @@ +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){ + String[] sentenceAr = sentence.split(" "); + int size=sentenceAr.length; + + for (int i=0;i 0 && number <= words.length) { + return words[number-1]; + } else { + return "Number = " + number + " is out Of Bound"; + } + + } + + /** + * 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; + if (searchForEven) { + + for (int i = 0; i < number.length(); i++) { + int n = Character.getNumericValue(number.charAt(i)); + if (n % 2 == 0) { + count++; + } + } + return count; + } else { + + for (int i = 0; i < number.length(); i++) { + int n = Character.getNumericValue(number.charAt(i)); + if (n % 2 == 1) { + 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) { + String wordALower = wordA.toLowerCase(); + String wordBLower = wordB.toLowerCase(); + + if (wordALower.compareTo(wordBLower) < 0) { + return wordA; + } else if (wordBLower.compareTo(wordALower) < 0) { + return wordB; + } else { + return "Both words are equal."; + } + } +} diff --git a/Answers/40230112089/src/test/java/StringTest.java b/Answers/40230112089/src/test/java/StringTest.java new file mode 100644 index 0000000..9d976bb --- /dev/null +++ b/Answers/40230112089/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("Happy", 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/40230112089/target/classes/Advanced.class b/Answers/40230112089/target/classes/Advanced.class new file mode 100644 index 0000000..3235fe8 Binary files /dev/null and b/Answers/40230112089/target/classes/Advanced.class differ diff --git a/Answers/40230112089/target/classes/Warmup.class b/Answers/40230112089/target/classes/Warmup.class new file mode 100644 index 0000000..5c5b915 Binary files /dev/null and b/Answers/40230112089/target/classes/Warmup.class differ diff --git a/Answers/40230112089/target/test-classes/StringTest.class b/Answers/40230112089/target/test-classes/StringTest.class new file mode 100644 index 0000000..464d0c3 Binary files /dev/null and b/Answers/40230112089/target/test-classes/StringTest.class differ diff --git a/Base Structure/.DS_Store b/Base Structure/.DS_Store new file mode 100644 index 0000000..24070f3 Binary files /dev/null and b/Base Structure/.DS_Store differ diff --git a/Base Structure/src/.DS_Store b/Base Structure/src/.DS_Store new file mode 100644 index 0000000..cbe4971 Binary files /dev/null and b/Base Structure/src/.DS_Store differ diff --git a/Base Structure/src/main/.DS_Store b/Base Structure/src/main/.DS_Store new file mode 100644 index 0000000..1cf17f4 Binary files /dev/null and b/Base Structure/src/main/.DS_Store differ diff --git a/Base Structure/src/main/java/Advanced.java b/Base Structure/src/main/java/Advanced.java index 4af5eae..4c195e5 100644 --- a/Base Structure/src/main/java/Advanced.java +++ b/Base Structure/src/main/java/Advanced.java @@ -10,7 +10,23 @@ public class Advanced { */ public String wordCensor(String sentence, String word, String newWord){ - return null; + String[] sentenceAr = sentence.split(" "); + int size=sentenceAr.length; + + for (int i=0;i 0 && number <= words.length) { + return words[number-1]; + } else { + return "Number = " + number + " is out Of Bound"; + } + } /** @@ -16,7 +22,26 @@ public String wordFinder(String sentence, int number) { * @return if searchForEven is true ? return the number of even numbers : return the number of odd numbers */ public int oddEvenCounter(String number, boolean searchForEven) { - return -1; + int count = 0; + if (searchForEven) { + + for (int i = 0; i < number.length(); i++) { + int n = Character.getNumericValue(number.charAt(i)); + if (n % 2 == 0) { + count++; + } + } + return count; + } else { + + for (int i = 0; i < number.length(); i++) { + int n = Character.getNumericValue(number.charAt(i)); + if (n % 2 == 1) { + count++; + } + } + return count; + } } /** @@ -25,6 +50,15 @@ public int oddEvenCounter(String number, boolean searchForEven) { * @return The word that is first in alphabet column */ public String firstWord(String wordA, String wordB) { - return null; + String wordALower = wordA.toLowerCase(); + String wordBLower = wordB.toLowerCase(); + + if (wordALower.compareTo(wordBLower) < 0) { + return wordA; + } else if (wordBLower.compareTo(wordALower) < 0) { + return wordB; + } else { + return "Both words are equal."; + } } } diff --git a/Base Structure/src/test/java/StringTest.java b/Base Structure/src/test/java/StringTest.java index 3e13bf7..9d976bb 100644 --- a/Base Structure/src/test/java/StringTest.java +++ b/Base Structure/src/test/java/StringTest.java @@ -7,8 +7,8 @@ public class StringTest { 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)); + assertEquals("Happy", warmup.wordFinder("Happy New Term", 1)); + assertEquals("Number = 4 is out Of Bound", warmup.wordFinder("Hello From Java", 4)); } @Test public void oddEvenCounter_test(){