Skip to content

Update and rename How To Send.txt to 40130212055 #4

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

Open
wants to merge 1 commit 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
134 changes: 134 additions & 0 deletions Answers/40130212055
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
لطفا از پروژه خودتون یک کپی بگیرید
کپی را در این فولدر پیست کنید
نام پروژه‌ای که پیست کردید را به شماره دانشجویی خودتون تغییر بدید
40130212055 amirrezasolhjo
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.