Skip to content

lab completed #57

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 5 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
67 changes: 60 additions & 7 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.zipcoder;


import java.util.Locale;

/**
* @author tariq
*/
Expand All @@ -14,8 +16,23 @@ public class StringsAndThings {
* countYZ("day fez"); // Should return 2
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
public Integer countYZ(String input) {
Integer counter = 0; //counter for loop
String[] wordsArray = input.toLowerCase().split(" "); //split string up into words by delimiter "space", ignoring case

//for the length of the array, check the last letter in each individual word of the wordsArray and compare to y or z
//if either y or z are found, increase the counter by 1
for (int i = 0; i < wordsArray.length; i++) {
String wordyz = wordsArray[i];
int len = wordyz.length()-1;

if (Character.isLetter(wordyz.charAt(len))) {
if (wordyz.charAt(len) == 'y' || (wordyz.charAt(len) == 'z')) {
counter++;
}
}
}
return counter;
}

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

return base.replaceAll(remove, ""); //replaces remove string with empty string
}

/**
Expand All @@ -40,7 +58,27 @@ public String removeString(String base, String remove){
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
//convert string to a character array
char[] isAndNot = input.toLowerCase().toCharArray();

//counters for 'is' and 'not' to later compare for Boolean
Integer isCount = 0;
Integer notCount = 0;

//check to see if sequence of chars 'i' and 's' and if so, increase isCount
for (int i = 0; i < isAndNot.length-1; i++) {
if (input.charAt(i) == 'i' && input.charAt(i + 1) == 's') {
isCount++;
}
}
//check to see if sequence of chars 'n', 'o', 't', and if so, increase notCount
for (int i = 0; i < isAndNot.length-2; i++) {
if (input.charAt(i) == 'n' && input.charAt(i+1) == 'o' && input.charAt(i+2) == 't') {
notCount++;
}
}

return isCount.equals(notCount);
}

/**
Expand All @@ -50,8 +88,15 @@ public Boolean containsEqualNumberOfIsAndNot(String input){
* gHappy("xxgxx") // Should return false
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
return null;
public Boolean gIsHappy(String input) {

for (int i = 1; i < input.length()-1; i++) {
if((input.charAt(i) == 'g' && input.charAt(i+1) != 'g')
&& (input.charAt(i) == 'g' && input.charAt(i-1) != 'g')) {
return false;
}
}
return true;
}


Expand All @@ -63,6 +108,14 @@ public Boolean gIsHappy(String input){
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
Integer 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;
}
}
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.