From d6e812dd05da8affb174a7a315173377406ad103 Mon Sep 17 00:00:00 2001 From: Anndraj <143296285+Anndrj@users.noreply.github.com> Date: Sun, 3 Mar 2024 20:03:12 +0330 Subject: [PATCH] Update and rename How To Send.txt to 40130212055 My student idea and my project --- Answers/40130212055 | 134 ++++++++++++++++++++++++++++++++++++++++ Answers/How To Send.txt | 3 - 2 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 Answers/40130212055 delete mode 100644 Answers/How To Send.txt diff --git a/Answers/40130212055 b/Answers/40130212055 new file mode 100644 index 0000000..1359d9b --- /dev/null +++ b/Answers/40130212055 @@ -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(); + } + +} + 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