Skip to content
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
49 changes: 44 additions & 5 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package io.zipcoder;


import com.sun.org.apache.xpath.internal.operations.Bool;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author tariq
*/
Expand All @@ -15,7 +20,14 @@ public class StringsAndThings {
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
String[] wordsOfString = input.split(" ");
int counter = 0;
for (int i = 0; i < wordsOfString.length; i++) {
if (wordsOfString[i].endsWith("y") || wordsOfString[i].endsWith("z")) {
counter++;
}
}
return counter;
}

/**
Expand All @@ -28,7 +40,7 @@ public Integer countYZ(String input){
* removeString("Hello there", "x") // Should return "Hello there"
*/
public String removeString(String base, String remove){
return null;
return base.replace(remove, "");
}

/**
Expand All @@ -40,7 +52,19 @@ public String removeString(String base, String remove){
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
int inputLength = input.length(); //11

String inputWithoutIs = removeString(input, "is"); //"th not"
int inputWOLength = inputWithoutIs.length(); //7
int diffOfIs = inputLength - inputWOLength; //11-7 = 4
int numberOfIs = diffOfIs/2; //4/2 2 is the size of "is"

String inputWithoutNot = removeString(input, "not"); //"this is "
int inputWONotLength = inputWithoutNot.length(); //8
int diffOfNot = inputLength - inputWONotLength; // 11-8 = 3
int numberOfNot = diffOfNot/3; //3/3 =1 3 is the size of "not"

return numberOfIs == numberOfNot;
}

/**
Expand All @@ -51,7 +75,15 @@ public Boolean containsEqualNumberOfIsAndNot(String input){
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
return null;
//check if g is to the left or right
boolean isGHappy = false;
Pattern ggs = Pattern.compile("gg");
Matcher foundGG = ggs.matcher(input);
if (foundGG.find()) {
String goodbyeGG = removeString(input, "gg");
isGHappy = !goodbyeGG.contains("g");
}
return isGHappy; //returning true or false
}


Expand All @@ -63,6 +95,13 @@ public Boolean gIsHappy(String input){
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
int counter = 0;
for (int i = 0; i < input.length() - 2; i++) {
if (input.charAt(i) == input.charAt(i + 1) && (input.charAt(i + 1) == input.charAt(i + 2))) {
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); //correcting the assertion for test case
}

}
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.