Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Answers/40230112037/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Answers/40230112037/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

406 changes: 406 additions & 0 deletions Answers/40230112037/.idea/dbnavigator.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Answers/40230112037/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Answers/40230112037/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Answers/40230112037/.idea/libraries/junit_jupiter.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Answers/40230112037/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions Answers/40230112037/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Answers/40230112037/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Answers/40230112037/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>StringMaster</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.8.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
55 changes: 55 additions & 0 deletions Answers/40230112037/src/main/java/Advanced.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

42 changes: 42 additions & 0 deletions Answers/40230112037/src/main/java/Warmup.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
41 changes: 41 additions & 0 deletions Answers/40230112037/src/test/java/StringTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Binary file added Answers/40230112037/target/classes/Advanced.class
Binary file not shown.
Binary file added Answers/40230112037/target/classes/Warmup.class
Binary file not shown.
Binary file not shown.