Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Homework #8

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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/40230112119/.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/40230112119/.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/40230112119/.idea/dbnavigator.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Answers/40230112119/.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/40230112119/.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/40230112119/.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/40230112119/.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/40230112119/.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/40230112119/.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/40230112119/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>
76 changes: 76 additions & 0 deletions Answers/40230112119/src/main/java/Advanced.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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[] sep = sentence.split(" ");
for (int i = 0; i < sep.length; i++) {
if (sep[i].equals(word)) {
sep[i] = newWord;
}
}
String result = String.valueOf(sep[0]);
for (int i = 1; i < sep.length; i++) {
result += " " + sep[i];
}

return result;

}

/**
* 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){
char[] letterf = firstName.toCharArray();
char[] letterl = lastName.toCharArray();
letterf[0] = Character.toUpperCase(letterf[0]);
letterl[0] = Character.toUpperCase(letterl[0]);
for (int i = 1; i < letterf.length; i++) {
letterf[i] = Character.toLowerCase(letterf[i]);
}
for (int i = 1; i < letterl.length; i++) {
letterl[i] = Character.toLowerCase(letterl[i]);
}
if (lastName.equals(" ")) {
return String.valueOf(letterf);
}
else {
String result = String.valueOf(letterf) + " " + String.valueOf(letterl);
return result;
}
}

/**
* 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) {
char[] a = word.toCharArray();
String newWord = "";
int i = 0, j = 0;
while (j < a.length) {
if (a[i] == a[j])
j++;
else {
newWord += a[i];
i = j;
j++;
}
}
newWord += a[j - 1];
return newWord;
}
}

Loading