Skip to content

strings and things lab #37

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 2 commits into
base: master
Choose a base branch
from
Open
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
71 changes: 65 additions & 6 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* @author tariq
*/
public class StringsAndThings {
public class StringsAndThings<counter> {

/**
* Given a string, count the number of words ending in 'y' or 'z' -- so the 'y' in "heavy" and the 'z' in "fez" count,
Expand All @@ -15,9 +15,25 @@ public class StringsAndThings {
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
Integer counter = 0;
int howLong = input.length();
input = input.toLowerCase();

for(int i = 0; i < howLong; i++) {
if (input.charAt(i) == 'y' || input.charAt(i) == 'z') {
if(i < howLong-1 && !Character.isLetter(input.charAt(i + 1))) {
counter++;
} else if (i == howLong-1) {
counter++;
}
}
}
return counter;

}



/**
* Given two strings, base and remove, return a version of the base string where all instances of the remove string have
* been removed (not case sensitive). You may assume that the remove string is length 1 or more.
Expand All @@ -28,7 +44,17 @@ public Integer countYZ(String input){
* removeString("Hello there", "x") // Should return "Hello there"
*/
public String removeString(String base, String remove){
return null;


/* (int i = 0; i < base.length(); i++) {
for (int j = 0; j < remove.length(); j++) {
if (base.charAt(i) == remove.charAt(0)) {

}
}
}*/

return base.replaceAll(remove,"");
}

/**
Expand All @@ -40,7 +66,28 @@ public String removeString(String base, String remove){
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
int isCount = 0;
int notCount = 0;
for (int i = 0; i < input.length()-1; i++){

if (input.substring(i, i+2).equals("is")){
isCount++;
} else if ( i+3 <= input.length()){
if (input.substring(i, i+3).equals("not")) {
notCount++;
}
}
}

if (isCount == notCount) {
return true;
}else {
return false;
}




}

/**
Expand All @@ -51,7 +98,12 @@ public Boolean containsEqualNumberOfIsAndNot(String input){
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
return null;
for (int i = 0; i < input.length(); i++){
if (i == i) {
return true;
}
}
return false;
}


Expand All @@ -63,6 +115,13 @@ public Boolean gIsHappy(String input){
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
Integer counter = 0;
for (int i = 0; i < input.length() - 2; i++){
char tmp = input.charAt(i);
if (tmp == input.charAt(i+1) && tmp == input.charAt(i+2)){
counter++;
}
}
return counter;
}
}