Skip to content

Raymond Fitzgerald #51

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: master
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
83 changes: 73 additions & 10 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,22 @@ public class StringsAndThings {
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
int count = 0;
String[] arrayOfWords = input.split(" ");
for (int i = 0; i < arrayOfWords.length; i++) {
String word = arrayOfWords[i];
int numberOfCharactersInWord = word.length();
int lastIndex = numberOfCharactersInWord -1;
char lastCharacter = word.charAt(lastIndex);
if(lastCharacter == 'y' || lastCharacter == 'z'){

count++;

}
//if the last character of word is equals to y or z

}
return count;
}

/**
Expand All @@ -27,31 +42,68 @@ public Integer countYZ(String input){
* removeString("Hello there", "e") // Should return "Hllo thr"
* removeString("Hello there", "x") // Should return "Hello there"
*/
//
//nested loop

public String removeString(String base, String remove){
return null;
}
String answer = base.replaceAll(remove, "");

return answer;
}
//
/**
* Given a string, return true if the number of appearances of "is" anywhere in the string is equal
* to the number of appearances of "not" anywhere in the string (case sensitive)
* Given a string, return true if the number of appearances of "is" anywhere in
* the string is equal to the number of appearances of "not" anywhere in the string
* (case sensitive)
*
* example : containsEqualNumberOfIsAndNot("This is not") // Should return false
* containsEqualNumberOfIsAndNot("This is notnot") // Should return true
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
//find the number of "is" appearances
//find the number of "not appearances
//compare number of appearances

int countIs = 0;
int countNot = 0;
int indexOf = input.indexOf("not");
while (indexOf >= 0){
input = input.replaceFirst("not", " ");
indexOf = input.indexOf("not");
countNot++;
}
indexOf = input.indexOf("is");

while (indexOf >= 0){
input = input.replaceFirst("is" , " ");
indexOf = input.indexOf("is");
countIs++;
}


return countIs == countNot;
}

/**
* We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right.
* We'll say that a lowercase 'g' in a string is "happy" if there is another
* 'g' immediately to its left or right.
* Return true if all the g's in the given string are happy.
* example : gHappy("xxggxx") // Should return true
* gHappy("xxgxx") // Should return false
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
return null;

public Boolean gIsHappy(String input) {
boolean returnMe = true;
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) == 'g') {
if (input.charAt(i + 1) != 'g' && input.charAt(i - 1) != 'g') {
returnMe = false;
}
}
}
return returnMe;
}


Expand All @@ -62,7 +114,18 @@ public Boolean gIsHappy(String input){
* countTriple("xxxabyyyycd") // Should return 3
* countTriple("a") // Should return 0
*/
/*
* identify the number of 3x repeating characters
* have that number of 3x repeating characters add to a counter
* */
public Integer countTriple(String input){
return null;
int counter = 0;
for (int i = 1; i < input.length() - 1; i++){
if(input.charAt(i) == input.charAt(i - 1) && input.charAt(i) == input.charAt(i + 1)){

counter++;
}
}
return counter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void gIsHappyTest2(){
@Test
public void gIsHappyTest3(){
Boolean actual = stringsAndThings.gIsHappy("xxggyygxx");
Assert.assertTrue(actual);
Assert.assertFalse(actual);
}

}
Binary file added target/classes/io/zipcoder/StringsAndThings.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.