From f81fa9721b5157b7a3417072f2b53862b6f37852 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Mon, 8 Jul 2024 13:26:17 +0000 Subject: [PATCH 1/9] Setting up GitHub Classroom Feedback From 56aae647a54f170bed93f99acd0d46bfd9b20e6d Mon Sep 17 00:00:00 2001 From: Devi Date: Mon, 8 Jul 2024 09:31:07 -0400 Subject: [PATCH 2/9] first commit --- .../assessment1/part1/BasicArrayUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtils.java index ef714b5..33cd7b0 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/BasicArrayUtils.java @@ -9,7 +9,7 @@ public class BasicArrayUtils { * @return the first element in the array */ public static String getFirstElement(String[] stringArray) { - return null; + return stringArray[0]; } /** @@ -17,7 +17,7 @@ public static String getFirstElement(String[] stringArray) { * @return the second element in the array */ public static String getSecondElement(String[] stringArray) { - return null; + return stringArray[1]; } /** @@ -25,7 +25,7 @@ public static String getSecondElement(String[] stringArray) { * @return the last element in the array */ public static String getLastElement(String[] stringArray) { - return null; + return stringArray[stringArray.length-1]; } /** @@ -33,6 +33,6 @@ public static String getLastElement(String[] stringArray) { * @return the second to last element in the array */ public static String getSecondToLastElement(String[] stringArray) { - return null; + return stringArray[stringArray.length-2]; } } From eba0de1c2651e20892e86ac857ceb49a0a9cf896 Mon Sep 17 00:00:00 2001 From: Devi Date: Mon, 8 Jul 2024 09:46:51 -0400 Subject: [PATCH 3/9] finished basic arrayutil and stringutil --- .../assessment1/part1/BasicStringUtils.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/BasicStringUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part1/BasicStringUtils.java index ca13f2d..b50fa12 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part1/BasicStringUtils.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/BasicStringUtils.java @@ -9,7 +9,11 @@ public class BasicStringUtils { * @return string with identical content, and the first character capitalized */ public static String camelCase(String str) { - return null; + String subString1 = str.substring(0,1); + String subString2 = str.substring(1,str.length()); + String subStringCap = subString1.toUpperCase(); + + return subStringCap+subString2; } /** @@ -17,7 +21,8 @@ public static String camelCase(String str) { * @return string with identical contents, in the reverse order */ public static String reverse(String str) { - return null; + StringBuilder revStr = new StringBuilder(str); + return revStr.reverse().toString(); } /** @@ -25,7 +30,11 @@ public static String reverse(String str) { * @return string with identical contents, in reverse order, with first character capitalized */ public static String reverseThenCamelCase(String str) { - return null; + StringBuilder str2 = new StringBuilder(str); + String str2Rev = str2.reverse().toString(); + String str2RevCap = camelCase(str2Rev); + + return str2RevCap; } @@ -34,7 +43,9 @@ public static String reverseThenCamelCase(String str) { * @return string with identical contents excluding first and last character */ public static String removeFirstAndLastCharacter(String str) { - return null; + String strRemovedEnds = str.substring(1, str.length()-1); + + return strRemovedEnds; } /** @@ -42,6 +53,18 @@ public static String removeFirstAndLastCharacter(String str) { * @return string with identical characters, each with opposite casing */ public static String invertCasing(String str) { - return null; + String[] individualCharsAsStrings = str.split(""); + StringBuilder casedString = new StringBuilder(); + + for (int i = 0; i < str.length(); i++){ + if (!individualCharsAsStrings[i].equals(individualCharsAsStrings[i].toUpperCase())){ + casedString.append(individualCharsAsStrings[i].toUpperCase()); + } + else { + casedString.append(individualCharsAsStrings[i].toLowerCase()); + } + } + + return casedString.toString(); } } From 1386df91133c56289f6ffa60ac70534d22e5a33f Mon Sep 17 00:00:00 2001 From: Devi Date: Mon, 8 Jul 2024 10:17:21 -0400 Subject: [PATCH 4/9] finished part 1 --- .../assessment1/part1/IntegerArrayUtils.java | 21 ++++++++++++--- .../assessment1/part1/IntegerUtils.java | 19 ++++++++++--- .../part1/RockPaperSissorsEvaluator.java | 27 ++++++++++++++++--- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtils.java index 68d82ec..d6d213b 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerArrayUtils.java @@ -9,7 +9,16 @@ public class IntegerArrayUtils { * @return the sum of `intArray` */ public static Integer getSum(Integer[] intArray) { - return null; +// int sum = 0; +// for (int element : intArray){ +// sum = sum + intArray[element]; +// } +// return sum; + int sum = 0; + for (int i = 0; i < intArray.length; i++){ + sum = sum + intArray[i]; + } + return sum; } /** @@ -17,7 +26,11 @@ public static Integer getSum(Integer[] intArray) { * @return the product of `intArray` */ public static Integer getProduct(Integer[] intArray) { - return null; + int product = 1; + for (int i = 0; i < intArray.length; i++){ + product = product * intArray[i]; + } + return product; } /** @@ -25,6 +38,8 @@ public static Integer getProduct(Integer[] intArray) { * @return the sum of `intArray` divided by number of elements in `intArray` */ public static Double getAverage(Integer[] intArray) { - return null; + int sum = getSum(intArray); + double avg = sum / intArray.length; + return avg; } } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java index eccbb6c..31f4294 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java @@ -11,7 +11,11 @@ public class IntegerUtils { * @return the sum of all integers between 0 and not including `n` */ public static Integer getSumOfN(Integer n) { - return null; + int sum = 0; + for (int i = n; i > 0; i--){ + sum = sum + i; + } + return sum; } /** @@ -19,7 +23,11 @@ public static Integer getSumOfN(Integer n) { * @return the product of all integers between 0 and not including `n` */ public static Integer getProductOfN(Integer n) { - return null; + int product = 1; + for (int i = n; i > 0; i--){ + product = product * i; + } + return product; } /** @@ -27,6 +35,11 @@ public static Integer getProductOfN(Integer n) { * @return integer with identical digits in the reverse order */ public static Integer reverseDigits(Integer val) { - return null; + String intString = Integer.toString(val); + // i stole my code from the string utils reverse method i made in step 1; + StringBuilder intStringSBRev = new StringBuilder(intString); + String intStringRevRev = intStringSBRev.reverse().toString(); + + return Integer.parseInt(intStringRevRev); } } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluator.java b/src/main/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluator.java index 9495445..6730617 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluator.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/RockPaperSissorsEvaluator.java @@ -13,7 +13,14 @@ public class RockPaperSissorsEvaluator { * @return the respective winning move */ public String getWinningMove(String handSign) { - return null; + switch (handSign){ + case (SCISSOR): + return ROCK; + case (ROCK): + return PAPER; + default: + return SCISSOR; + } } /** @@ -21,7 +28,14 @@ public String getWinningMove(String handSign) { * @return the respective losing move */ public String getLosingMove(String handSign) { - return null; + switch (handSign){ + case (SCISSOR): + return PAPER; + case (PAPER): + return ROCK; + default: + return SCISSOR; + } } /** @@ -30,6 +44,13 @@ public String getLosingMove(String handSign) { * @return a string representative of the winning hand sign between the two players */ public String getWinner(String handSignOfPlayer1, String handSignOfPlayer2) { - return null; + if (handSignOfPlayer1.equals(getWinningMove(handSignOfPlayer2))){ + return handSignOfPlayer1; + } + else if (handSignOfPlayer2.equals(getWinningMove(handSignOfPlayer1))){ + return handSignOfPlayer2; + } else{ + return "tie"; + } } } From a3a032552c2c0a04060d51072f0eed7b5a57d914 Mon Sep 17 00:00:00 2001 From: Devi Date: Mon, 8 Jul 2024 11:41:53 -0400 Subject: [PATCH 5/9] completed p2.1 and p2.2 --- .../assessment1/part2/ArrayUtils.java | 96 +++++++++++++++++-- .../assessment1/part2/MultiplesDeleter.java | 86 ++++++++++++++++- 2 files changed, 172 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/assessment1/part2/ArrayUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part2/ArrayUtils.java index bb9995a..102aecb 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part2/ArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part2/ArrayUtils.java @@ -1,5 +1,10 @@ package com.zipcodewilmington.assessment1.part2; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + /** * Created by leon on 2/16/18. */ @@ -11,7 +16,15 @@ public class ArrayUtils { * Given an array of objects, named `objectArray`, and an object `objectToCount`, return the number of times the `objectToCount` appears in the `objectArray` */ public static Integer getNumberOfOccurrences(Object[] objectArray, Object objectToCount) { - return null; + int counter = 0; + + for (int i = 0; i < objectArray.length; i++){ + if (objectArray[i].equals(objectToCount)){ + counter++; + } + } + + return counter; } /** @@ -20,8 +33,38 @@ public static Integer getNumberOfOccurrences(Object[] objectArray, Object object * @return an array with identical content excluding the specified `objectToRemove` * Given an array of objects, name `objectArray`, and an object `objectToRemove`, return an array of objects with identical contents excluding `objectToRemove` */ - public static Object[] removeValue(Object[] objectArray, Object objectToRemove) { - return null; + public static Integer[] removeValue(Object[] objectArray, Object objectToRemove) { +// ArrayList objectArrayList = new ArrayList<>(); +// int counter = 0; +// +// while(counter < objectArray.length-1){ +// if (objectArray[counter].equals(objectToRemove)){ +// counter++; +// } else{ +// objectArrayList.add(objectArray[counter]); +// counter++; +// } +// } +// return objectArrayList.toArray(); + int numberOfOccurances = getNumberOfOccurrences(objectArray, objectToRemove); + int counter = 0; + int arrayIndexCounter = 0; + Integer[] occuranceArray = new Integer[objectArray.length - numberOfOccurances]; + + while(counter < objectArray.length){ + if (objectArray[counter].equals(objectToRemove)) { + counter++; + } else { + occuranceArray[arrayIndexCounter] = (Integer) objectArray[counter]; + arrayIndexCounter++; + counter++; + + } + + } + return occuranceArray; + //i changed the method to return an Integer[] because I was having test issues of the compiler + //parsing my original object[] into an Integer[] for the test } /** @@ -30,7 +73,24 @@ public static Object[] removeValue(Object[] objectArray, Object objectToRemove) * given an array of objects, named `objectArray` return the most frequently occuring object in the array */ public static Object getMostCommon(Object[] objectArray) { - return null; + HashMap map = new HashMap<>(); + + for (int i = 0; i < objectArray.length; i++){ + Integer occurance = map.getOrDefault(objectArray[i], 0); + occurance++; + map.put(objectArray[i], occurance); + } + Integer max = 0; + Object answer =0; + + for (Map.Entry entry : map.entrySet()){ + if (entry.getValue() > max){ + max = entry.getValue(); + answer = entry.getKey(); + } + } + + return answer; } @@ -40,7 +100,25 @@ public static Object getMostCommon(Object[] objectArray) { * given an array of objects, named `objectArray` return the least frequently occuring object in the array */ public static Object getLeastCommon(Object[] objectArray) { - return null; + HashMap map = new HashMap<>(); + + for (int i = 0; i < objectArray.length; i++){ + Integer occurance = map.getOrDefault(objectArray[i], 0); + occurance++; + map.put(objectArray[i], occurance); + } + Integer min = 10; + Object answer =0; + + for (Map.Entry entry : map.entrySet()){ + if (entry.getValue() < min){ + min = entry.getValue(); + answer = entry.getKey(); + } + } + + return answer; + } /** @@ -50,6 +128,12 @@ public static Object getLeastCommon(Object[] objectArray) { * given two arrays `objectArray` and `objectArrayToAdd`, return an array containing all elements in `objectArray` and `objectArrayToAdd` */ public static Object[] mergeArrays(Object[] objectArray, Object[] objectArrayToAdd) { - return null; +// Object[] merger = Arrays.copyOf(objectArrayToAdd, objectArray.length+objectArrayToAdd.length); +// System.arraycopy(objectArray, 0, objectArray.length + objectArrayToAdd.length); + + Object[] result = Arrays.copyOf(objectArray, objectArray.length + objectArrayToAdd.length); + System.arraycopy(objectArrayToAdd, 0, result, objectArray.length, objectArrayToAdd.length); + return result; + } } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleter.java b/src/main/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleter.java index a348b0d..5d46185 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleter.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part2/MultiplesDeleter.java @@ -1,5 +1,9 @@ package com.zipcodewilmington.assessment1.part2; +import org.junit.Assert; + +import java.util.ArrayList; + /** * Created by leon on 2/16/18. */ @@ -10,7 +14,35 @@ public class MultiplesDeleter { * given an array of integers, named `ints` return an identical array with evens removed */ public Integer[] deleteEvens(Integer[] ints) { - return null; +// ArrayList deletedEvens = new ArrayList<>(); +// for (int element : ints){ +// if (element > ints.length-1){ +// break; +// } +// else if (ints[element]%2 ==0){ +// continue; +// } else { +// deletedEvens.add(ints[element]); +// } +// } +// return deletedEvens.toArray().toString(); + + int evenOccurence = 0; + for (int i : ints){ + if (!(i % 2 == 0)){ + evenOccurence++; + } + } + Integer[] removedEvens = new Integer[evenOccurence]; + int i = -1; + for (int element : ints) { + if (!(element % 2 == 0)) { + removedEvens[i + 1] = element; + i++; + + } + } + return removedEvens; } /** @@ -19,7 +51,22 @@ public Integer[] deleteEvens(Integer[] ints) { * given an array of integers, named `ints` return an identical array with odds removed */ public Integer[] deleteOdds(Integer[] ints) { - return null; + int oddOccurence = 0; + for (int i : ints){ + if (i % 2 == 0) { + oddOccurence++; + } + } + Integer[] removedOdds = new Integer[oddOccurence]; + int i = -1; + for (int element : ints) { + if (element % 2 == 0) { + removedOdds[i + 1] = element; + i++; + + } + } + return removedOdds; } /** @@ -28,7 +75,22 @@ public Integer[] deleteOdds(Integer[] ints) { * given an array of integers, named `ints` return an identical array with numbers indivisible by 3 removed */ public Integer[] deleteMultiplesOf3(Integer[] ints) { - return null; + int noThreeMultOccurance = 0; + for (int i : ints){ + if (i%3 != 0) { + noThreeMultOccurance++; + } + } + Integer[] removed3Multiples = new Integer[noThreeMultOccurance]; + int i = -1; + for (int element : ints) { + if (element % 3 != 0) { + removed3Multiples[i + 1] = element; + i++; + + } + } + return removed3Multiples; } /** @@ -38,6 +100,22 @@ public Integer[] deleteMultiplesOf3(Integer[] ints) { * given an array of integers, named `ints` return an identical array with numbers indivisible by `multiple` removed */ public Integer[] deleteMultiplesOfN(Integer[] ints, int multiple) { - return null; + int nOccurance = 0; + for (int i : ints){ + if (i % multiple == 0) { + nOccurance++; + } + } + Integer[] removedMultiples = new Integer[nOccurance]; + int i = -1; + for (int element : ints) { + if (element % multiple != 0) { + removedMultiples[i + 1] = element; + i++; + + } + } + return removedMultiples; + } } From 0f1e49ead3b0e652e9fe0663b6337494632db8ed Mon Sep 17 00:00:00 2001 From: Devi Date: Mon, 8 Jul 2024 13:04:48 -0400 Subject: [PATCH 6/9] got stuck on petowners, moving onto jumper --- .../assessment1/part2/StringUtils.java | 27 +++++++++++--- .../assessment1/part3/Cat.java | 31 ++++++++++++++-- .../assessment1/part3/Dog.java | 32 +++++++++++++++- .../assessment1/part3/Pet.java | 26 +++++++++++-- .../assessment1/part3/PetOwner.java | 37 ++++++++++++++++++- .../assessment1/part4/Jumper.java | 16 ++++++++ 6 files changed, 154 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/assessment1/part2/StringUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part2/StringUtils.java index fc403e5..7cf242f 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part2/StringUtils.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part2/StringUtils.java @@ -11,7 +11,8 @@ public class StringUtils { * given a string containing words delimited by spaces, representative of a sentence, return an array of strings, each element representative of a respective word in the sentence */ public static String[] getWords(String sentence) { - return null; + String[] words = sentence.split(" "); + return words; } @@ -21,7 +22,9 @@ public static String[] getWords(String sentence) { * given a string containing words delimited by spaces, representative of a sentence, return the first word of the sentence */ public static String getFirstWord(String sentence) { - return null; + String[] words = getWords(sentence); + + return words[0]; } /** @@ -30,7 +33,12 @@ public static String getFirstWord(String sentence) { * given a string containing words delimited by spaces, representative of a sentence, return the first word with identical contents in reverse order */ public static String reverseFirstWord(String sentence) { - return null; + String[] words = getWords(sentence); + String firstWord = words[0]; + StringBuilder wordSB = new StringBuilder(firstWord); + StringBuilder revWordSB = wordSB.reverse(); + + return revWordSB.toString(); } /** @@ -39,7 +47,13 @@ public static String reverseFirstWord(String sentence) { * given a string containing words delimited by spaces, representative of a sentence, return the first word with identical contents in reverse order with the first character capitalized */ public static String reverseFirstWordThenCamelCase(String sentence) { - return null; + String revvedFirstWord = reverseFirstWord(sentence); + + String subString1 = revvedFirstWord.substring(0,1); + String subString2 = revvedFirstWord.substring(1,revvedFirstWord.length()); + String subStringCap = subString1.toUpperCase(); + + return subStringCap+subString2; } @@ -50,7 +64,10 @@ public static String reverseFirstWordThenCamelCase(String sentence) { * given a string and index, return an identical string excluding the character at the specified index */ public static String removeCharacterAtIndex(String str, int index) { - return null; + StringBuilder removedChar = new StringBuilder(str); + removedChar = removedChar.deleteCharAt(index); + + return removedChar.toString(); } } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/Cat.java b/src/main/java/com/zipcodewilmington/assessment1/part3/Cat.java index e731b77..a2b678b 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part3/Cat.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/Cat.java @@ -8,21 +8,44 @@ public class Cat extends Pet { * @param name name of this Cat * @param age age of this Cat */ - public Cat(String name, Integer age) { + private String name; + private int age; + @Override + public Integer getAge() { + return age; + } + public void setAge(int age) { + this.age = age; + } + + @Override + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + public Cat(String name, Integer age) { + this.name = name; + this.age = age; } /** * @param age age of this Cat */ public Cat(Integer age) { + name = "Cat name"; + this.age = age; } /** * @param name name of this Cat */ public Cat(String name) { - + this.name = name; + age = 0; } /** @@ -32,12 +55,14 @@ public Cat(String name) { * age is 0 */ public Cat() { + name = "Cat name"; + age = 0; } /** * @return meow as a string */ public String speak() { - return null; + return "Meow"; } } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/Dog.java b/src/main/java/com/zipcodewilmington/assessment1/part3/Dog.java index 0c775fd..8773a8f 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part3/Dog.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/Dog.java @@ -8,20 +8,46 @@ public class Dog extends Pet { * @param name name of this Dog * @param age age of this dog */ - public Dog(String name, Integer age) { + private String name; + private int age; + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + @Override + public Integer getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Dog(String name, Integer age) { + this.name = name; + this.age = age; } /** * @param age age of this dog */ public Dog(Integer age) { + this.age = age; + name = "Dog name"; } /** * @param name name of this dog */ public Dog(String name) { + this.name = name; + age = 0; } @@ -32,12 +58,14 @@ public Dog(String name) { * age is 0 */ public Dog() { + name = "Dog name"; + age = 0; } /** * @return bark as a string */ public String speak() { - return null; + return "Bark"; } } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java b/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java index 3c925da..bfdcda8 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java @@ -8,13 +8,28 @@ public abstract class Pet implements Animal { * nullary constructor * by default, pet has age of 0; name of ""; */ + private String name; + private int age; + private PetOwner petOwner; + + public PetOwner getPetOwner() { + return petOwner; + } + public void setPetOwner(PetOwner petOwner) { + this.petOwner = petOwner; + } + public Pet() { + name = "Pet name"; + age = 0; } /** * @param name name of this pet */ public Pet(String name) { + this.name = name; + age = 0; } @@ -22,6 +37,8 @@ public Pet(String name) { * @param age age of this pet */ public Pet(int age) { + this.age = age; + name = "Pet name"; } /** @@ -29,20 +46,22 @@ public Pet(int age) { * @param age age of this pet */ public Pet(String name, int age) { + this.name = name; + this.age = age; } /** * @return name of this pet */ public String getName() { - return null; + return name; } /** * @return age of this pet */ public Integer getAge() { - return null; + return age; } /** @@ -50,12 +69,13 @@ public Integer getAge() { * ensure this instance of `Pet` is added to the owner's composite `pets` list */ public void setOwner(PetOwner newPetOwner) { + setPetOwner(newPetOwner); } /** * @return PetOwner object whose composite `pets` collection contains this Pet instance */ public PetOwner getOwner() { - return null; + return getPetOwner(); } } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java b/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java index 7bbf2ab..17d7cc5 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java @@ -1,5 +1,7 @@ package com.zipcodewilmington.assessment1.part3; +import java.util.Arrays; + /** * Created by leon on 2/16/18. */ @@ -8,20 +10,46 @@ public class PetOwner { * @param name name of the owner of the Pet * @param pets array of Pet object */ + private String name; + private Pet[] pets; + + public void setName(String name) { + this.name = name; + } + public void setPets(Pet[] pets) { + this.pets = pets; + } + public PetOwner(String name, Pet... pets) { + this.name = name; + this.pets = pets; } /** * @param pet pet to be added to the composite collection of Pets */ public void addPet(Pet pet) { + Pet[] addedPet = new Pet[getNumberOfPets()+1]; + addedPet[addedPet.length-1] = pet; + pets = addedPet; } /** * @param pet pet to be removed from the composite collection Pets */ public void removePet(Pet pet) { - + int lengthOfPets = getPets().length; + Pet[] removedPet = new Pet[lengthOfPets]; + Pet[] oldPetArray = new Pet[getPets().length]; + oldPetArray = getPets(); + int removedPetIndex = -1; + for (int i = 0; i < oldPetArray.length; i++){ + if(!oldPetArray[i].equals(pet)){ + removedPet[removedPetIndex] = oldPetArray[i]; + removedPetIndex++; + } else; + } + pets = removedPet; } /** @@ -29,13 +57,18 @@ public void removePet(Pet pet) { * @return true if I own this pet */ public Boolean isOwnerOf(Pet pet) { - return null; + if(name.contains((CharSequence) pet)){ + return true; + } else{ + return false; + } } /** * @return the age of the Pet object whose age field is the lowest amongst all Pets in this class */ public Integer getYoungetPetAge() { + return null; } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java b/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java index f881e9c..3df056f 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java @@ -6,6 +6,22 @@ public class Jumper { * Complete the function below. */ public int jumps(int k, int j) { + int counter = 0; + if (k < j){ + return k; + } else if (k > j){ + + for (int i = j; i < k; i++){ + if (i * counter < k){ + counter++; + } else { + return j - (i * counter % k); + } + } + int howManyTimes = j%k; + return j - howManyTimes; + } + return -1; } } From 4a66fb8a936549496a018f7563fc24f2e1cccd83 Mon Sep 17 00:00:00 2001 From: Devi Date: Mon, 8 Jul 2024 15:35:21 -0400 Subject: [PATCH 7/9] finished palindrome --- .../assessment1/part3/PetOwner.java | 7 +- .../assessment1/part5/Palindrome.java | 87 ++++++++++++++++++- 2 files changed, 89 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java b/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java index 17d7cc5..4fe1899 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java @@ -1,6 +1,7 @@ package com.zipcodewilmington.assessment1.part3; import java.util.Arrays; +import java.util.HashMap; /** * Created by leon on 2/16/18. @@ -94,20 +95,20 @@ public Float getAveragePetAge() { * @return the number of Pet objects stored in this class */ public Integer getNumberOfPets() { - return null; + return pets.length; } /** * @return the name property of the Pet */ public String getName() { - return null; + return name; } /** * @return array representation of animals owned by this PetOwner */ public Pet[] getPets() { - return null; + return pets; } } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part5/Palindrome.java b/src/main/java/com/zipcodewilmington/assessment1/part5/Palindrome.java index 89e2016..0e1e452 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part5/Palindrome.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part5/Palindrome.java @@ -1,8 +1,91 @@ package com.zipcodewilmington.assessment1.part5; +import java.util.ArrayList; +import java.util.Arrays; + public class Palindrome { - public Integer countPalindromes(String input){ - return null; + public Integer countPalindromes(String input) { + int length = input.length(); + int palindromeCounter = length; + + for(int i=0; i 0 && temp[i].equals(inputChar[inputChar.length-j -1])){ +// palindromeCounter++; +// j++; +// } +// } +// return palindromeCounter; + +// for (int j = 0; j < inputChar.length; j++){ +// +// for (int i = 0; i < inputChar.length/2; i++) { +// String[] temp = new String[]{inputChar[i]}; +// if(i > 0 && temp[i].equals(inputChar[inputChar.length-j-1])) { +// palindromeCounter++; +// palindromeCounter++; +// } else { +// palindromeCounter++; +// } +// } +// } +// return palindromeCounter; + +// String[] inputChar = input.split(""); +// StringBuilder charSB = new StringBuilder(input); +// for (int i = 0; i < inputChar.length; i++){ +// for (int j = 0; j < inputChar[i].length(); i++){ +// String sBChar = charSB.charAt(i); +// if(inputChar[i].equals(charSB.charAt(i))){} +// } +// } + +// String[] inputChar = input.split(""); +// int palinDromeCounter = 0; +// int i = 0; +// for (String element : inputChar){ +// if(i < inputChar.length && element.equals(inputChar[i])){ +// palinDromeCounter++; +// } else if (i+1 < inputChar.length && inputChar[i].equals(inputChar[i+1])){ +// palinDromeCounter++; +// } else {palinDromeCounter++; +// } +// } + +// for (int i = 0; i < inputChar.length; i++){ +// if(i > 0 && inputChar[i].equals(inputChar[i-1]) && inputChar[i].equals(inputChar[i+1])){ +// palinDromeCounter++; +// } else if (i+1 < inputChar.length && inputChar[i].equals(inputChar[i+1])){ +// palinDromeCounter++; +// } else {palinDromeCounter++; +// } +// } +// +// return null; } } + From 0efd50816c4640425ba9f62356926e98f26c6b20 Mon Sep 17 00:00:00 2001 From: Devi Date: Mon, 8 Jul 2024 16:17:52 -0400 Subject: [PATCH 8/9] push --- .../assessment1/part3/Pet.java | 13 +++++---- .../assessment1/part4/Jumper.java | 29 ++++++++++++------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java b/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java index bfdcda8..d50d909 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/Pet.java @@ -12,9 +12,6 @@ public abstract class Pet implements Animal { private int age; private PetOwner petOwner; - public PetOwner getPetOwner() { - return petOwner; - } public void setPetOwner(PetOwner petOwner) { this.petOwner = petOwner; } @@ -32,6 +29,12 @@ public Pet(String name) { age = 0; } + public Pet(PetOwner petOwner){ + this.petOwner = petOwner; + name = "Pet name"; + age = 0; + } + /** * @param age age of this pet @@ -69,13 +72,13 @@ public Integer getAge() { * ensure this instance of `Pet` is added to the owner's composite `pets` list */ public void setOwner(PetOwner newPetOwner) { - setPetOwner(newPetOwner); + this.petOwner = newPetOwner; } /** * @return PetOwner object whose composite `pets` collection contains this Pet instance */ public PetOwner getOwner() { - return getPetOwner(); + return petOwner; } } diff --git a/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java b/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java index 3df056f..ac4a8f0 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part4/Jumper.java @@ -6,22 +6,31 @@ public class Jumper { * Complete the function below. */ public int jumps(int k, int j) { - int counter = 0; if (k < j){ return k; - } else if (k > j){ - - for (int i = j; i < k; i++){ - if (i * counter < k){ - counter++; - } else { - return j - (i * counter % k); + } else if (k == j){ + return 1; + } + else if(k > j) { + for (int i = j; i <= k; i++) { + if (j + (i) > k) { + return i; + } else{ } } - int howManyTimes = j%k; - return j - howManyTimes; } +// for (int i = j; i < k; i++){ +// if (i * counter < k){ +// counter++; +// } else { +// return j - (i * counter % k); +// } +// } +// int howManyTimes = j%k; +// return j - howManyTimes; + + return -1; } } From 7feaf2a28f5685008a3277c427ff3cce930fbf25 Mon Sep 17 00:00:00 2001 From: Devi Date: Mon, 8 Jul 2024 16:26:57 -0400 Subject: [PATCH 9/9] finished but ran outta time --- .../java/com/zipcodewilmington/assessment1/part3/PetOwner.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java b/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java index 4fe1899..984e9fd 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part3/PetOwner.java @@ -58,7 +58,8 @@ public void removePet(Pet pet) { * @return true if I own this pet */ public Boolean isOwnerOf(Pet pet) { - if(name.contains((CharSequence) pet)){ + + if(name.contains((CharSequence) pet)){ return true; } else{ return false;