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

Manny finished StringsAndThings #45

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
124 changes: 105 additions & 19 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,127 @@ public class StringsAndThings {
* but not the 'y' in "yellow" (not case sensitive). We'll say that a y or z is at the end of a word if there is not an alphabetic
* letter immediately following it. (Note: Character.isLetter(char) tests if a char is an alphabetic letter.)
* example : countYZ("fez day"); // Should return 2
* countYZ("day fez"); // Should return 2
* countYZ("day fyyyz"); // Should return 2
* countYZ("day fez"); // Should return 2
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
public Integer countYZ(String input) {
int count = 0;
String[] inputSplit = input.split(" ");
for (int i = 0; i < inputSplit.length; i++) {
if (inputSplit[i].charAt(inputSplit.length - 1) == 'y' ||
inputSplit[i].charAt(inputSplit.length - 1) == 'z') {
}
count++;
}
return count;
}
/*
Character findYZ[] = {'y', 'z'};
int count = 0;

for (int i = 0; i < findYZ.length; i++) {
Character character = findYZ[i];
count = count + 1;
}
return count;
*/
/**
* 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.
* Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x".
*
* <p>
* example : removeString("Hello there", "llo") // Should return "He there"
* removeString("Hello there", "e") // Should return "Hllo thr"
* removeString("Hello there", "x") // Should return "Hello there"
* removeString("Hello there", "e") // Should return "Hllo thr"
* removeString("Hello there", "x") // Should return "Hello there"
*/
public String removeString(String base, String remove){
return null;
public String removeString(String base, String remove) {
String newString = base.replaceAll(remove, "");
return newString;
}

/**
* 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)
*
* <p>
* example : containsEqualNumberOfIsAndNot("This is not") // Should return false
* containsEqualNumberOfIsAndNot("This is notnot") // Should return true
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
* containsEqualNumberOfIsAndNot("This is notnot") // Should return true
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
}

public Boolean containsEqualNumberOfIsAndNot(String input) {
int countIs = 0;
int countNot = 0;
int index = input.indexOf("not");
String currString = input;

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

while(index >= 0) {
currString = currString.replaceFirst("is", "");
index = currString.indexOf("is");
countIs++;
}
return countIs == countNot;
}
/*
CharSequence isString = "is";
CharSequence notString = "not";
String[] inputSplit = input.split(" ");
for (int i = 0; i < inputSplit.length; i++) {
if (inputSplit[i].contains(isString)) {
countIs++;
}
if (inputSplit[i].contains(notString)) {
countNot++;
}
}
if (countIs == countNot) {
return true;
} else {
return false;
}
*/
/*
if (input.contains(isString)) {
countIs++;
} if (input.contains(notString)) {
countNot++;
}
if(countIs == countNot) {
return true;
} else {
return false;
}
*/
/**
* 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;
// if current char is g, if char + 1 or -1 is g then return true
public Boolean gIsHappy(String input) {
boolean bool = 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') {
bool = false;
}
}
}
return bool;
}

// for (int j = i + 1; j < input.length(); j++) {
// if (input.charAt(i) == input.charAt(j)) {
// return true;
//

/**
* We'll say that a "triple" in a string is a char appearing three times in a row.
Expand All @@ -63,6 +141,14 @@ public Boolean gIsHappy(String input){
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
int count = 0;
for (int i = 0; i < input.length() - 1; i++) {
if (input.charAt(i) == input.charAt(i + 1)) {
if (input.charAt(i + 1) == 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);
}

}
Binary file added target/classes/io/zipcoder/StringsAndThings.class
Binary file not shown.
5 changes: 5 additions & 0 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Generated by Maven
#Wed Jun 30 18:51:11 EDT 2021
groupId=com.github.zipcodewilmington
artifactId=strings-and-things
version=1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/manny/dev/Labs/stringsandthings.maven/src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/Users/manny/dev/Labs/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/RemoveStringTest.java
/Users/manny/dev/Labs/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java
/Users/manny/dev/Labs/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/CountYZTest.java
/Users/manny/dev/Labs/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/ContainsEqualNumberOfIsAndNotTest.java
/Users/manny/dev/Labs/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/CountTripleTest.java
Binary file added target/strings-and-things-1.0.0.jar
Binary file not shown.
Loading