From e5513c9b6fab8284541eb91245fc0b79c1e01b0d Mon Sep 17 00:00:00 2001 From: Ellis John Date: Sun, 31 Oct 2021 21:39:16 -0400 Subject: [PATCH 1/4] lab --- .../MathUtilities.java | 55 ++++++++++++------- .../StringUtilities.java | 10 ++-- .../ZipcodeRocks.java | 2 +- .../mathutilities/TestAddition.java | 2 +- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java index 8076dfe..510ee6e 100644 --- a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java +++ b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java @@ -11,7 +11,8 @@ public class MathUtilities { * @return sum of `baseValue` and `difference` */ public Integer add(int baseValue, int difference) { - return null; + + return baseValue + difference; } /** @@ -20,7 +21,7 @@ public Integer add(int baseValue, int difference) { * @return sum of `baseValue` and `difference` */ public Long add(long baseValue, long difference) { - return null; + return baseValue + difference; } /** @@ -28,8 +29,12 @@ public Long add(long baseValue, long difference) { * @param difference value to add to starting value * @return sum of `baseValue` and `difference` */ - public Short add(short baseValue, short difference) { - return null; + public int add(short baseValue, short difference) { + + int i = baseValue; + int j = difference; + return i + j; + } /** @@ -37,8 +42,17 @@ public Short add(short baseValue, short difference) { * @param difference value to add to starting value * @return sum of `baseValue` and `difference` */ - public Byte add(byte baseValue, byte difference) { - return null; + public int add(byte baseValue, byte difference) { + Byte a = new Byte(baseValue); + Byte b = new Byte(difference); + int a2 = a.intValue(); + int b2 = b.intValue(); + +// double i = baseValue; +// double j = difference; + return a2 + b2; + + } /** @@ -47,7 +61,9 @@ public Byte add(byte baseValue, byte difference) { * @return sum of `baseValue` and `difference` */ public Float add(float baseValue, float difference) { - return null; + Float a = baseValue; + Float b = difference; + return a + b; } /** @@ -116,7 +132,7 @@ public Double subtract(double baseValue, double difference) { /** * @param dividend value to be divided - * @param divisor value to divide by + * @param divisor value to divide by * @return division of `dividend` by `divisor */ public Integer divide(int dividend, int divisor) { @@ -125,7 +141,7 @@ public Integer divide(int dividend, int divisor) { /** * @param dividend value to be divided - * @param divisor value to divide by + * @param divisor value to divide by * @return division of `dividend` by `divisor */ public Long divide(long dividend, long divisor) { @@ -134,7 +150,7 @@ public Long divide(long dividend, long divisor) { /** * @param dividend value to be divided - * @param divisor value to divide by + * @param divisor value to divide by * @return division of `dividend` by `divisor */ public Short divide(short dividend, short divisor) { @@ -143,7 +159,7 @@ public Short divide(short dividend, short divisor) { /** * @param dividend value to be divided - * @param divisor value to divide by + * @param divisor value to divide by * @return division of `dividend` by `divisor */ public Byte divide(byte dividend, byte divisor) { @@ -152,7 +168,7 @@ public Byte divide(byte dividend, byte divisor) { /** * @param dividend value to be divided - * @param divisor value to divide by + * @param divisor value to divide by * @return division of `dividend` by `divisor */ public Float divide(float dividend, float divisor) { @@ -161,7 +177,7 @@ public Float divide(float dividend, float divisor) { /** * @param dividend value to be divided - * @param divisor value to divide by + * @param divisor value to divide by * @return division of `dividend` by `divisor */ public Double divide(double dividend, double divisor) { @@ -171,7 +187,7 @@ public Double divide(double dividend, double divisor) { /** * @param multiplicand value to be multiplied - * @param multiplier value to multiply by + * @param multiplier value to multiply by * @return product of `multiplicand` by `multiplier` */ public Integer multiply(int multiplicand, int multiplier) { @@ -180,7 +196,7 @@ public Integer multiply(int multiplicand, int multiplier) { /** * @param multiplicand value to be multiplied - * @param multiplier value to multiply by + * @param multiplier value to multiply by * @return product of `multiplicand` by `multiplier` */ public Long multiply(long multiplicand, long multiplier) { @@ -189,15 +205,16 @@ public Long multiply(long multiplicand, long multiplier) { /** * @param multiplicand value to be multiplied - * @param multiplier value to multiply by + * @param multiplier value to multiply by * @return product of `multiplicand` by `multiplier` */ public Short multiply(short multiplicand, short multiplier) { return null; } + /** * @param multiplicand value to be multiplied - * @param multiplier value to multiply by + * @param multiplier value to multiply by * @return product of `multiplicand` by `multiplier` */ public Byte multiply(byte multiplicand, byte multiplier) { @@ -206,7 +223,7 @@ public Byte multiply(byte multiplicand, byte multiplier) { /** * @param multiplicand value to be multiplied - * @param multiplier value to multiply by + * @param multiplier value to multiply by * @return product of `multiplicand` by `multiplier` */ public Float multiply(float multiplicand, float multiplier) { @@ -215,7 +232,7 @@ public Float multiply(float multiplicand, float multiplier) { /** * @param multiplicand value to be multiplied - * @param multiplier value to multiply by + * @param multiplier value to multiply by * @return product of `multiplicand` by `multiplier` */ public Double multiply(double multiplicand, double multiplier) { diff --git a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java index 2f776a9..96ca816 100644 --- a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java +++ b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java @@ -8,7 +8,8 @@ public class StringUtilities { * @return `Hello World` as a string */ public static String getHelloWorld() { - return null; + + return "Hello World"; } /** @@ -17,7 +18,7 @@ public static String getHelloWorld() { * @return the concatenation of two strings, `firstSegment`, and `secondSegment` */ public static String concatenation(String firstSegment, String secondSegment){ - return null; + return firstSegment + secondSegment; } /** @@ -34,7 +35,7 @@ public static String concatenation(int firstSegment, String secondSegment){ * @return the first 3 characters of `input` */ public static String getPrefix(String input){ - return null; + return input.substring(0, 2); } /** @@ -42,7 +43,8 @@ public static String getPrefix(String input){ * @return the last 3 characters of `input` */ public static String getSuffix(String input){ - return null; + return input.substring(input.length() - 2, input.length()); + } /** diff --git a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java index 819f21b..fdef5bb 100644 --- a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java +++ b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java @@ -5,6 +5,6 @@ */ public class ZipcodeRocks { public static void main(String[] args) { -// System.out.println("Zipcode Rocks!"); + System.out.println("Zipcode Rocks!"); } } diff --git a/src/test/java/com/zipcodewilmington/danny_do_better_exercises/mathutilities/TestAddition.java b/src/test/java/com/zipcodewilmington/danny_do_better_exercises/mathutilities/TestAddition.java index 03981ff..7ea4bf7 100644 --- a/src/test/java/com/zipcodewilmington/danny_do_better_exercises/mathutilities/TestAddition.java +++ b/src/test/java/com/zipcodewilmington/danny_do_better_exercises/mathutilities/TestAddition.java @@ -42,7 +42,7 @@ public void testShortAddition() { short addedValue = 7; short expected = 16391; // : When - short actual = mathUtils.add(baseValue, addedValue); + short actual = (short) mathUtils.add(baseValue, addedValue); // : Then assertEquals(expected, actual); } From 96e4d11fc0f93b6751da7c28e24c4be1b3ca7520 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Mon, 1 Nov 2021 08:15:50 -0400 Subject: [PATCH 2/4] lab --- .../MathUtilities.java | 69 +++++++++++-------- .../StringUtilities.java | 12 ++-- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java index 510ee6e..8d97110 100644 --- a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java +++ b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.java @@ -1,5 +1,7 @@ package com.zipcodewilmington.danny_do_better_exercises; +import java.nio.ByteBuffer; + /** * Created by dan on 6/14/17. */ @@ -42,15 +44,10 @@ public int add(short baseValue, short difference) { * @param difference value to add to starting value * @return sum of `baseValue` and `difference` */ - public int add(byte baseValue, byte difference) { - Byte a = new Byte(baseValue); - Byte b = new Byte(difference); - int a2 = a.intValue(); - int b2 = b.intValue(); + public Byte add(byte baseValue, byte difference) { + + return (byte)(baseValue + difference); -// double i = baseValue; -// double j = difference; - return a2 + b2; } @@ -61,9 +58,7 @@ public int add(byte baseValue, byte difference) { * @return sum of `baseValue` and `difference` */ public Float add(float baseValue, float difference) { - Float a = baseValue; - Float b = difference; - return a + b; + return baseValue + difference; } /** @@ -72,7 +67,8 @@ public Float add(float baseValue, float difference) { * @return sum of `baseValue` and `difference` */ public Double add(double baseValue, double difference) { - return null; + return baseValue + difference; + } /** @@ -81,7 +77,8 @@ public Double add(double baseValue, double difference) { * @return difference between `baseValue` and `difference` */ public Integer subtract(int baseValue, int difference) { - return null; + + return baseValue - difference; } /** @@ -90,7 +87,7 @@ public Integer subtract(int baseValue, int difference) { * @return difference between `baseValue` and `difference` */ public Long subtract(long baseValue, long difference) { - return null; + return baseValue - difference; } /** @@ -99,7 +96,8 @@ public Long subtract(long baseValue, long difference) { * @return difference between `baseValue` and `difference` */ public Short subtract(short baseValue, short difference) { - return null; + + return (short)(baseValue - difference); } /** @@ -108,7 +106,8 @@ public Short subtract(short baseValue, short difference) { * @return difference between `baseValue` and `difference` */ public Byte subtract(byte baseValue, byte difference) { - return null; + + return (byte)(baseValue - difference); } /** @@ -117,7 +116,8 @@ public Byte subtract(byte baseValue, byte difference) { * @return difference between `baseValue` and `difference` */ public Float subtract(float baseValue, float difference) { - return null; + + return baseValue - difference; } /** @@ -126,7 +126,8 @@ public Float subtract(float baseValue, float difference) { * @return difference between `baseValue` and `difference` */ public Double subtract(double baseValue, double difference) { - return null; + + return baseValue - difference; } @@ -136,7 +137,8 @@ public Double subtract(double baseValue, double difference) { * @return division of `dividend` by `divisor */ public Integer divide(int dividend, int divisor) { - return null; + + return dividend / divisor; } /** @@ -145,7 +147,8 @@ public Integer divide(int dividend, int divisor) { * @return division of `dividend` by `divisor */ public Long divide(long dividend, long divisor) { - return null; + + return dividend / divisor; } /** @@ -154,7 +157,7 @@ public Long divide(long dividend, long divisor) { * @return division of `dividend` by `divisor */ public Short divide(short dividend, short divisor) { - return null; + return (short)(dividend / divisor); } /** @@ -163,7 +166,7 @@ public Short divide(short dividend, short divisor) { * @return division of `dividend` by `divisor */ public Byte divide(byte dividend, byte divisor) { - return null; + return (byte)(dividend / divisor); } /** @@ -172,7 +175,8 @@ public Byte divide(byte dividend, byte divisor) { * @return division of `dividend` by `divisor */ public Float divide(float dividend, float divisor) { - return null; + + return dividend / divisor; } /** @@ -181,7 +185,7 @@ public Float divide(float dividend, float divisor) { * @return division of `dividend` by `divisor */ public Double divide(double dividend, double divisor) { - return null; + return dividend / divisor; } @@ -191,7 +195,8 @@ public Double divide(double dividend, double divisor) { * @return product of `multiplicand` by `multiplier` */ public Integer multiply(int multiplicand, int multiplier) { - return null; + + return multiplicand * multiplier; } /** @@ -200,7 +205,8 @@ public Integer multiply(int multiplicand, int multiplier) { * @return product of `multiplicand` by `multiplier` */ public Long multiply(long multiplicand, long multiplier) { - return null; + + return multiplicand * multiplier; } /** @@ -209,7 +215,8 @@ public Long multiply(long multiplicand, long multiplier) { * @return product of `multiplicand` by `multiplier` */ public Short multiply(short multiplicand, short multiplier) { - return null; + + return (short)(multiplicand * multiplier); } /** @@ -218,7 +225,7 @@ public Short multiply(short multiplicand, short multiplier) { * @return product of `multiplicand` by `multiplier` */ public Byte multiply(byte multiplicand, byte multiplier) { - return null; + return (byte)(multiplicand * multiplier); } /** @@ -227,7 +234,8 @@ public Byte multiply(byte multiplicand, byte multiplier) { * @return product of `multiplicand` by `multiplier` */ public Float multiply(float multiplicand, float multiplier) { - return null; + + return multiplicand * multiplier; } /** @@ -236,6 +244,7 @@ public Float multiply(float multiplicand, float multiplier) { * @return product of `multiplicand` by `multiplier` */ public Double multiply(double multiplicand, double multiplier) { - return null; + + return multiplicand * multiplier; } } diff --git a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java index 96ca816..accef96 100644 --- a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java +++ b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java @@ -18,7 +18,7 @@ public static String getHelloWorld() { * @return the concatenation of two strings, `firstSegment`, and `secondSegment` */ public static String concatenation(String firstSegment, String secondSegment){ - return firstSegment + secondSegment; + return firstSegment.concat(secondSegment); } /** @@ -27,7 +27,8 @@ public static String concatenation(String firstSegment, String secondSegment){ * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment` */ public static String concatenation(int firstSegment, String secondSegment){ - return null; + + return firstSegment + secondSegment; } /** @@ -53,7 +54,8 @@ public static String getSuffix(String input){ * @return the equivalence of two strings, `inputValue` and `comparableValue` */ public static Boolean compareTwoStrings(String inputValue, String comparableValue){ - return null; + if (inputValue.equals(comparableValue)) + return true; } /** @@ -61,7 +63,9 @@ public static Boolean compareTwoStrings(String inputValue, String comparableValu * @return the middle character of `inputValue` */ public static Character getMiddleCharacter(String inputValue){ - return null; + int length = inputValue.length(); + int middle = length / 2; + return inputValue.substring(middle); // not sure from here } /** From 6b16a0d91d96247106864e31e5cb6d3296118b27 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Tue, 2 Nov 2021 10:46:36 -0400 Subject: [PATCH 3/4] message --- GroupDemoRecap | 1 + add-jellis.txt.save | 1 + .../PredicateUtilities.java | 27 +++++++++++--- .../StringUtilities.java | 37 ++++++++++++++----- 4 files changed, 52 insertions(+), 14 deletions(-) create mode 160000 GroupDemoRecap create mode 100644 add-jellis.txt.save diff --git a/GroupDemoRecap b/GroupDemoRecap new file mode 160000 index 0000000..a37da59 --- /dev/null +++ b/GroupDemoRecap @@ -0,0 +1 @@ +Subproject commit a37da59c88b05cba3e89e207c93ca20039ce7b8a diff --git a/add-jellis.txt.save b/add-jellis.txt.save new file mode 100644 index 0000000..539a70f --- /dev/null +++ b/add-jellis.txt.save @@ -0,0 +1 @@ +just made this diff --git a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java index cb5f822..e0dae4b 100644 --- a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java +++ b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java @@ -10,6 +10,10 @@ public class PredicateUtilities { * @return true if `x` is greater than `y` */ public Boolean isGreaterThan(int x, int y) { + + if (x > y) { + return true; + } return null; } @@ -19,7 +23,11 @@ public Boolean isGreaterThan(int x, int y) { * @return true if `x` is less than `y` */ public Boolean isLessThan(int x, int y) { - return null; + + if (x < y) { + return true; + } else + return false; } /** @@ -28,7 +36,12 @@ public Boolean isLessThan(int x, int y) { * @return true if `x` is greater than or equal to `y` */ public Boolean isGreaterThanOrEqualTo(int x, int y) { - return null; + + if (x >= y) { + return true; + } else { + return false; + } } /** @@ -37,7 +50,11 @@ public Boolean isGreaterThanOrEqualTo(int x, int y) { * @return true if `x` is less than or equal to `y` */ public Boolean isLessThanOrEqualTo(int x, int y) { - return null; + if (x <= y) { + return true; + } else { + return false; + } } @@ -45,14 +62,14 @@ public Boolean isLessThanOrEqualTo(int x, int y) { * @return true */ public Boolean returnTrue() { - return null; + return true; } /** * @return false */ public Boolean returnFalse() { - return null; + return false; } } \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java index accef96..1b20ce4 100644 --- a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java +++ b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java @@ -1,5 +1,8 @@ package com.zipcodewilmington.danny_do_better_exercises; +import java.util.ArrayList; +import java.util.Scanner; + /** * Created by dan on 6/14/17. */ @@ -36,7 +39,9 @@ public static String concatenation(int firstSegment, String secondSegment){ * @return the first 3 characters of `input` */ public static String getPrefix(String input){ - return input.substring(0, 2); + + + return input.substring(0, 3); } /** @@ -44,7 +49,8 @@ public static String getPrefix(String input){ * @return the last 3 characters of `input` */ public static String getSuffix(String input){ - return input.substring(input.length() - 2, input.length()); + int inputLength = input.length(); + return input.substring(inputLength - 3, inputLength); } @@ -53,19 +59,25 @@ public static String getSuffix(String input){ * @param comparableValue the value to be compared against * @return the equivalence of two strings, `inputValue` and `comparableValue` */ - public static Boolean compareTwoStrings(String inputValue, String comparableValue){ - if (inputValue.equals(comparableValue)) - return true; + public static Boolean compareTwoStrings(String inputValue, String comparableValue) { + if (inputValue.equals(comparableValue)) { + return true; + } return false; } + /** * @param inputValue the value input from user * @return the middle character of `inputValue` */ public static Character getMiddleCharacter(String inputValue){ - int length = inputValue.length(); - int middle = length / 2; - return inputValue.substring(middle); // not sure from here +// int length = inputValue.length(); +// int middle = length / 2; +// if (middle.length % 2 != 0) { +// char middleChar = length.length((1/2) -1); +// return middleChar; + + return null; } /** @@ -73,7 +85,14 @@ public static Character getMiddleCharacter(String inputValue){ * @return the first sequence of characters */ public static String getFirstWord(String spaceDelimitedString){ - return null; + Scanner scanWords = new Scanner(spaceDelimitedString); + ArrayList words = new ArrayList(); + + return words[0]; + +// while (scanWords.hasNext()) { +// words.add(scanWords.next()); +// } return words } /** From 85fd691845fcb303fdce9c623d3e4e3cfffa98e1 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Tue, 2 Nov 2021 13:57:18 -0400 Subject: [PATCH 4/4] message --- .../PredicateUtilities.java | 2 +- .../StringUtilities.java | 18 +++++++++++++----- .../TestStringUtilities.java | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java index e0dae4b..8d45407 100644 --- a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java +++ b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java @@ -14,7 +14,7 @@ public Boolean isGreaterThan(int x, int y) { if (x > y) { return true; } - return null; + return false; } /** diff --git a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java index 1b20ce4..2a5f591 100644 --- a/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java +++ b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java @@ -85,10 +85,15 @@ public static Character getMiddleCharacter(String inputValue){ * @return the first sequence of characters */ public static String getFirstWord(String spaceDelimitedString){ - Scanner scanWords = new Scanner(spaceDelimitedString); - ArrayList words = new ArrayList(); - return words[0]; + String[] str = spaceDelimitedString.split(" "); + String firstWord = str[0]; + return firstWord; + + + +// return null; +// return words[0]; // while (scanWords.hasNext()) { // words.add(scanWords.next()); @@ -100,7 +105,9 @@ public static String getFirstWord(String spaceDelimitedString){ * @return the second word of a string delimited by spaces. */ public static String getSecondWord(String spaceDelimitedString){ - return null; + String[] str = spaceDelimitedString.split(" "); + String secondWord = str[1]; + return secondWord; } /** @@ -108,6 +115,7 @@ public static String getSecondWord(String spaceDelimitedString){ * @return an identical string with characters in reverse order. */ public static String reverse(String stringToReverse){ - return null; + String newString = new StringBuffer(stringToReverse).reverse().toString(); + return newString; } } diff --git a/src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java b/src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java index 66a1fc0..ca499b1 100644 --- a/src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java +++ b/src/test/java/com/zipcodewilmington/danny_do_better_exercises/TestStringUtilities.java @@ -130,6 +130,8 @@ public void getTheMiddleCharOfZipcoder(){ // : Then Assert.assertEquals(expected.toString(), actual.toString()); + + }