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

bekhoda ke nmidonam in bara chie #3

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
134 changes: 134 additions & 0 deletions Answers/40130212055.txt
Original file line number Diff line number Diff line change
@@ -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();
}

}

3 changes: 0 additions & 3 deletions Answers/How To Send.txt

This file was deleted.

1 change: 1 addition & 0 deletions Base Structure/.idea/.name

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

6 changes: 6 additions & 0 deletions Base Structure/.idea/vcs.xml

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

6 changes: 6 additions & 0 deletions Base Structure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
49 changes: 46 additions & 3 deletions Base Structure/src/main/java/Advanced.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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();
}

}

35 changes: 32 additions & 3 deletions Base Structure/src/main/java/Warmup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion Base Structure/src/test/java/StringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified Base Structure/target/classes/Advanced.class
Binary file not shown.
Binary file modified Base Structure/target/classes/Warmup.class
Binary file not shown.
Binary file modified Base Structure/target/test-classes/StringTest.class
Binary file not shown.