Skip to content
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

I have added changes #1

Open
wants to merge 2 commits 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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
35 changes: 29 additions & 6 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.zipcoder;

import java.util.Arrays;

/**
* @author tariq
Expand All @@ -15,7 +16,14 @@ public class StringsAndThings {
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
int counter = 0;
String[] list = input.split(" "); //Decided not to use a string Builder, would be unnecessarily complex
for (int i = 0;i < list.length;i++){
if ((list[i].charAt(list[i].length()-1) == 'y') || ((list[i].charAt(list[i].length()-1) == 'z'))){
counter++;
}
}
return counter;
}

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

/**
Expand All @@ -39,8 +48,14 @@ public String removeString(String base, String remove){
* containsEqualNumberOfIsAndNot("This is notnot") // Should return true
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/

private int contains(String input, String word){
int starting_length = input.length();
int ending_length = input.replace(word,"").length();
return ((starting_length - ending_length) / word.length()); // How many instances of the word there where
}
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
return contains(input, "not") == contains(input, "is");
}

/**
Expand All @@ -51,7 +66,8 @@ public Boolean containsEqualNumberOfIsAndNot(String input){
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
return null;
int gg = contains(input, "gg");
return (gg == (contains(input, "g")-gg));
}


Expand All @@ -62,7 +78,14 @@ public Boolean gIsHappy(String input){
* countTriple("xxxabyyyycd") // Should return 3
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
public Integer countTriple(String input) {//Can't use contains() for this without calling it a LOT, not worth it
int count = 0; //What we will return
for (int i = 0; i < input.length()-2; i++) { // we count up to 2, don't want to go out of bounds
char c = input.charAt(i); //Save the char, then we can jump forward from that
if (c == input.charAt(i + 1) && c == input.charAt(i + 2)) {
count++;
}
}
return count;
}
}
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); // changed from assertTrue to assertFalse because it's not true. It's false
}

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