diff --git a/Answers/40130212055.txt b/Answers/40130212055.txt
new file mode 100644
index 0000000..2e14734
--- /dev/null
+++ b/Answers/40130212055.txt
@@ -0,0 +1,134 @@
+لطفا از پروژه خودتون یک کپی بگیرید
+کپی را در این فولدر پیست کنید
+نام پروژهای که پیست کردید را به شماره دانشجویی خودتون تغییر بدید
+40130212055
+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[] redult = sentence.split(" ");
+
+ if (number > 0 && number <= redult.length) {
+ return redult[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) {
+ String[] num = number.split("");
+ int count = 0;
+ for (String i : num) {
+ int num1 = Integer.parseInt(i);
+ if (searchForEven && num1 % 2 == 0) {
+ count++;
+ } else if (!searchForEven && num1 % 2 != 0) {
+ 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) {
+ int minLength = Math.min(wordA.length(), wordB.length());
+
+ for (int i = 0; i < minLength; i++) {
+ char char1 = Character.toLowerCase(wordA.charAt(i));
+ char char2 = Character.toLowerCase(wordB.charAt(i));
+
+ if (char1 < char2) {
+ return wordA;
+ } else if (char1 > char2) {
+ return wordB;
+ }
+ }
+
+ return minLength == wordA.length() ? wordA : wordB;
+ }
+}
+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){
+ StringBuilder sb = new StringBuilder();
+ String[] letter = sentence.split(" ");
+
+ for (int i = 0; i < letter.length; i++) {
+ if (letter[i].equals(word))
+ sb.append(newWord);
+ else
+ sb.append(letter[i]);
+
+ if (i < letter.length - 1)
+ sb.append(" ");
+
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * 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){
+
+ String normalizedFirstName = firstName.substring(0, 1).toUpperCase() + firstName.substring(1).toLowerCase();
+
+ String normalizedLastName = lastName.substring(0, 1).toUpperCase() + lastName.substring(1).toLowerCase();
+
+ String fullName = normalizedFirstName + " " + normalizedLastName;
+
+ return fullName;
+ }
+
+ /**
+ * 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 == null || word.isEmpty()) {
+ return word;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ char prevChar = '\0';
+
+ for (char currentChar : word.toCharArray()) {
+ if (currentChar != prevChar) {
+ sb.append(currentChar);
+ prevChar = currentChar;
+ }
+ }
+
+ return sb.toString();
+ }
+
+}
+
diff --git a/Answers/How To Send.txt b/Answers/How To Send.txt
deleted file mode 100644
index 96b559e..0000000
--- a/Answers/How To Send.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-لطفا از پروژه خودتون یک کپی بگیرید
-کپی را در این فولدر پیست کنید
-نام پروژهای که پیست کردید را به شماره دانشجویی خودتون تغییر بدید
\ No newline at end of file
diff --git a/Base Structure/.idea/.name b/Base Structure/.idea/.name
new file mode 100644
index 0000000..acd8f9b
--- /dev/null
+++ b/Base Structure/.idea/.name
@@ -0,0 +1 @@
+Warmup.java
\ No newline at end of file
diff --git a/Base Structure/.idea/vcs.xml b/Base Structure/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/Base Structure/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Base Structure/pom.xml b/Base Structure/pom.xml
index 6803a74..4d38f33 100644
--- a/Base Structure/pom.xml
+++ b/Base Structure/pom.xml
@@ -33,6 +33,12 @@
junit-jupiter
test
+
+ org.jetbrains
+ annotations
+ RELEASE
+ compile
+
\ No newline at end of file
diff --git a/Base Structure/src/main/java/Advanced.java b/Base Structure/src/main/java/Advanced.java
index 4af5eae..4ec2b55 100644
--- a/Base Structure/src/main/java/Advanced.java
+++ b/Base Structure/src/main/java/Advanced.java
@@ -10,7 +10,21 @@ public class Advanced {
*/
public String wordCensor(String sentence, String word, String newWord){
- return null;
+ StringBuilder sb = new StringBuilder();
+ String[] letter = sentence.split(" ");
+
+ for (int i = 0; i < letter.length; i++) {
+ if (letter[i].equals(word))
+ sb.append(newWord);
+ else
+ sb.append(letter[i]);
+
+ if (i < letter.length - 1)
+ sb.append(" ");
+
+ }
+
+ return sb.toString();
}
/**
@@ -20,7 +34,21 @@ public String wordCensor(String sentence, String word, String newWord){
* @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){
- return null;
+
+ String normalizedFirstName = firstName.substring(0, 1).toUpperCase() + firstName.substring(1).toLowerCase();
+
+ String normalizedLastName = lastName.substring(0, 1).toUpperCase() + lastName.substring(1).toLowerCase();
+
+ String fullName;
+
+ if(normalizedLastName.equals(" "))
+ {
+ fullName = normalizedFirstName;
+ }
+ else {
+ fullName = normalizedFirstName + " " + normalizedLastName;
+ }
+ return fullName;
}
/**
@@ -29,7 +57,22 @@ public String normalizingName(String firstName, String lastName){
* @return if word contains Consecutive repeated letters, one of the repeated letters should be omitted
*/
public String doubleChar(String word) {
- return null;
+ if (word == null || word.isEmpty()) {
+ return word;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ char prevChar = '\0';
+
+ for (char currentChar : word.toCharArray()) {
+ if (currentChar != prevChar) {
+ sb.append(currentChar);
+ prevChar = currentChar;
+ }
+ }
+
+ return sb.toString();
}
+
}
diff --git a/Base Structure/src/main/java/Warmup.java b/Base Structure/src/main/java/Warmup.java
index 2ae7eda..5ff581e 100644
--- a/Base Structure/src/main/java/Warmup.java
+++ b/Base Structure/src/main/java/Warmup.java
@@ -6,7 +6,13 @@ public class Warmup {
* @return is the number th word of the sentence
*/
public String wordFinder(String sentence, int number) {
- return null;
+ String[] redult = sentence.split(" ");
+
+ if (number > 0 && number <= redult.length) {
+ return redult[number - 1];
+ } else {
+ return " Number = " + number + " is out Of Bound";
+ }
}
/**
@@ -16,7 +22,17 @@ 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;
+ String[] num = number.split("");
+ int count = 0;
+ for (String i : num) {
+ int num1 = Integer.parseInt(i);
+ if (searchForEven && num1 % 2 == 0) {
+ count++;
+ } else if (!searchForEven && num1 % 2 != 0) {
+ count++;
+ }
+ }
+ return count;
}
/**
@@ -25,6 +41,19 @@ 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;
+ int minLength = Math.min(wordA.length(), wordB.length());
+
+ for (int i = 0; i < minLength; i++) {
+ char char1 = Character.toLowerCase(wordA.charAt(i));
+ char char2 = Character.toLowerCase(wordB.charAt(i));
+
+ if (char1 < char2) {
+ return wordA;
+ } else if (char1 > char2) {
+ return wordB;
+ }
+ }
+
+ return minLength == wordA.length() ? wordA : wordB;
}
}
diff --git a/Base Structure/src/test/java/StringTest.java b/Base Structure/src/test/java/StringTest.java
index 3e13bf7..95cc7d2 100644
--- a/Base Structure/src/test/java/StringTest.java
+++ b/Base Structure/src/test/java/StringTest.java
@@ -7,7 +7,7 @@ public class StringTest {
Advanced advanced = new Advanced();
@Test
public void wordFinder_test(){
- assertEquals("Tem", warmup.wordFinder("Happy New Term", 1));
+ assertEquals("Happy", warmup.wordFinder("Happy New Term", 1));
assertEquals(" Number = 4 is out Of Bound", warmup.wordFinder("Hello From Java", 4));
}
@Test
diff --git a/Base Structure/target/classes/Advanced.class b/Base Structure/target/classes/Advanced.class
index 3235fe8..8d45820 100644
Binary files a/Base Structure/target/classes/Advanced.class and b/Base Structure/target/classes/Advanced.class differ
diff --git a/Base Structure/target/classes/Warmup.class b/Base Structure/target/classes/Warmup.class
index 5c5b915..865bc7b 100644
Binary files a/Base Structure/target/classes/Warmup.class and b/Base Structure/target/classes/Warmup.class differ
diff --git a/Base Structure/target/test-classes/StringTest.class b/Base Structure/target/test-classes/StringTest.class
index 464d0c3..91e9fbe 100644
Binary files a/Base Structure/target/test-classes/StringTest.class and b/Base Structure/target/test-classes/StringTest.class differ