Skip to content
Open

Dond #12

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
128 changes: 128 additions & 0 deletions Answers/40230212055/Advanced.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import java.util.Objects;
import java.util.Scanner;

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[] sentence1 = sentence.split(" ");

int size = sentence1.length;

String word1 = word;


for(int i =0 ; i<size ; i++)
{
if (sentence1[i].equals(word1))
{
sentence1[i] = newWord;
break;
}
}

for(int i =1 ; i<size ; i++)
{
sentence1[0]+=" ";
sentence1[0]+=sentence1[i];
}
//****
return sentence1[0];


}

/**
* 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 firstname1 = firstName;
String lastname1 = lastName;
String [] firstname = firstname1.split("");
String [] lastname = lastname1.split("");
int size1 =firstname.length;
int size2 =lastname.length;


for (int i=0 ; i<size1 ; i++)
{
if (i==0)
{
firstname[0]=firstname[0].toUpperCase();
continue;
}
firstname[i]=firstname[i].toLowerCase();
firstname[0]+=firstname[i];
}
if(lastName==" ")
return firstname[0];

for (int i=0 ; i<size2 ; i++)
{
if (i==0)
{
lastname[0]=lastname[0].toUpperCase();
continue;
}
lastname[i]=lastname[i].toLowerCase();
lastname[0]+=lastname[i];
}
if (firstName==" ")
return lastname[0];
firstname[0]+=" ";
firstname[0]+=lastname[0];
//****
return firstname[0];
}

/**
* 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) {


String [] str2 = word.split("");
int size = str2.length;
String final1;

int a=str2[1].codePointAt(0);

for (int i=1 ; i<size-1 ; i++)
{
int shomaresh=0;
for(int j=i+1 ; j<size ; j++)
{
if (str2[i].codePointAt(0)==str2[j].codePointAt(0))
{
shomaresh++;
}
if(str2[i].codePointAt(0)!=str2[j].codePointAt(0))
{
str2[0]+=str2[i];
i+=shomaresh;
break;
}
}

}
str2[0]+=str2[size-1];

//****
return str2[0];
}
}

157 changes: 157 additions & 0 deletions Answers/40230212055/Warmup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import java.util.Scanner;

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) {
System.out.print("sentence: ");

String [] str = sentence.split(" ");

int size = str.length;
if (size<number)
{
return " Number = " +number+ " is out Of Bound" ;
}
else
return str[number-1];
//tanrin 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 number2 = Integer.parseInt(number) ;
int number3 = number2;
int shomaresh=0 ;

while(true)
{

if (number2==0)
break;
number2 = number2/10;
shomaresh ++;

}

boolean status1 = searchForEven;

if (status1==true)
{
int even=0;
for (int i=1 ; i<=shomaresh ; i++)
{

if(number3%2==0)
{
even++;
}
number3/=10;

}
return even;
}

else
{
int odd=0;

for (int i=1 ; i<=shomaresh ; i++)
{

if(number3%2==1)
{
odd++;
}

number3/=10;

}
//tamrin 2
return odd;

}



}

/**
* @param wordA --> first word
* @param wordB --> second word
* @return The word that is first in alphabet column
*/
public String firstWord(String wordA, String wordB) {


String string11 =wordA;
String string22 =wordB;
String[] str1 = string11.split("");
String[] str2 = string22.split("");


int i=0;
int b1=string11.length();
int b2=string22.length();

while(true)
{
/* if (str1[i]=="\0" && str2[i]!="\0")
{
System.out.println(string11);
break;
}
else if (str1[i]!="\0" && str2[i]=="\0")
{
System.out.println(string22);
break;

}
else
{
System.out.println(string22);

}
*/
if ((i)==b1)
{
return (string11);
}
if ((i)==b2)
{
return (string22);
}

if (str1[i].compareTo(str2[i])<0)
{

return (string11);
}

else if (str1[i].compareTo(str2[i])>0)
{

return (string22);

}

else
i++;

}


//tamrin3
}
}
1 change: 1 addition & 0 deletions test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testing