From df654d590f37ef8d79f611fbfeaa032ec5d733d3 Mon Sep 17 00:00:00 2001 From: Manny Date: Sat, 26 Jun 2021 14:35:44 -0400 Subject: [PATCH] Manny finished DanDoBetterDrills --- .../MathUtilities.java | 71 ++++++++++++------- .../PredicateUtilities.java | 33 +++++++-- .../StringUtilities.java | 39 +++++++--- .../ZipcodeRocks.java | 2 +- 4 files changed, 102 insertions(+), 43 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..b3c58b7 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,16 +11,17 @@ public class MathUtilities { * @return sum of `baseValue` and `difference` */ public Integer add(int baseValue, int difference) { - return null; + return baseValue + difference; } + /** * @param baseValue starting value * @param difference value to add to starting value * @return sum of `baseValue` and `difference` */ public Long add(long baseValue, long difference) { - return null; + return baseValue + difference; } /** @@ -29,7 +30,8 @@ public Long add(long baseValue, long difference) { * @return sum of `baseValue` and `difference` */ public Short add(short baseValue, short difference) { - return null; + Integer answer = baseValue + difference; + return answer.shortValue(); } /** @@ -38,7 +40,8 @@ public Short add(short baseValue, short difference) { * @return sum of `baseValue` and `difference` */ public Byte add(byte baseValue, byte difference) { - return null; + Integer answer = baseValue + difference; + return answer.byteValue(); } /** @@ -47,7 +50,8 @@ public Byte add(byte baseValue, byte difference) { * @return sum of `baseValue` and `difference` */ public Float add(float baseValue, float difference) { - return null; + float answer = baseValue + difference; + return answer; } /** @@ -56,7 +60,8 @@ public Float add(float baseValue, float difference) { * @return sum of `baseValue` and `difference` */ public Double add(double baseValue, double difference) { - return null; + double answer = baseValue + difference; + return answer; } /** @@ -65,7 +70,8 @@ public Double add(double baseValue, double difference) { * @return difference between `baseValue` and `difference` */ public Integer subtract(int baseValue, int difference) { - return null; + Integer answer = baseValue - difference; + return answer; } /** @@ -74,7 +80,8 @@ public Integer subtract(int baseValue, int difference) { * @return difference between `baseValue` and `difference` */ public Long subtract(long baseValue, long difference) { - return null; + Long answer = baseValue - difference; + return answer; } /** @@ -83,7 +90,8 @@ public Long subtract(long baseValue, long difference) { * @return difference between `baseValue` and `difference` */ public Short subtract(short baseValue, short difference) { - return null; + Integer answer = baseValue - difference; + return answer.shortValue(); } /** @@ -92,7 +100,8 @@ public Short subtract(short baseValue, short difference) { * @return difference between `baseValue` and `difference` */ public Byte subtract(byte baseValue, byte difference) { - return null; + Integer answer = baseValue - difference; + return answer.byteValue(); } /** @@ -101,7 +110,8 @@ public Byte subtract(byte baseValue, byte difference) { * @return difference between `baseValue` and `difference` */ public Float subtract(float baseValue, float difference) { - return null; + float answer = baseValue - difference; + return answer; } /** @@ -110,7 +120,8 @@ public Float subtract(float baseValue, float difference) { * @return difference between `baseValue` and `difference` */ public Double subtract(double baseValue, double difference) { - return null; + double answer = baseValue - difference; + return answer; } @@ -120,7 +131,8 @@ public Double subtract(double baseValue, double difference) { * @return division of `dividend` by `divisor */ public Integer divide(int dividend, int divisor) { - return null; + Integer answer = dividend / divisor; + return answer; } /** @@ -129,7 +141,8 @@ public Integer divide(int dividend, int divisor) { * @return division of `dividend` by `divisor */ public Long divide(long dividend, long divisor) { - return null; + Long answer = dividend / divisor; + return answer; } /** @@ -138,7 +151,8 @@ public Long divide(long dividend, long divisor) { * @return division of `dividend` by `divisor */ public Short divide(short dividend, short divisor) { - return null; + Integer answer = dividend / divisor; + return answer.shortValue(); } /** @@ -147,7 +161,8 @@ public Short divide(short dividend, short divisor) { * @return division of `dividend` by `divisor */ public Byte divide(byte dividend, byte divisor) { - return null; + Integer answer = dividend / divisor; + return answer.byteValue(); } /** @@ -156,7 +171,8 @@ public Byte divide(byte dividend, byte divisor) { * @return division of `dividend` by `divisor */ public Float divide(float dividend, float divisor) { - return null; + Float answer = dividend / divisor; + return answer; } /** @@ -165,7 +181,8 @@ public Float divide(float dividend, float divisor) { * @return division of `dividend` by `divisor */ public Double divide(double dividend, double divisor) { - return null; + Double answer = dividend / divisor; + return answer; } @@ -175,7 +192,8 @@ public Double divide(double dividend, double divisor) { * @return product of `multiplicand` by `multiplier` */ public Integer multiply(int multiplicand, int multiplier) { - return null; + Integer answer = multiplicand * multiplier; + return answer; } /** @@ -184,7 +202,8 @@ public Integer multiply(int multiplicand, int multiplier) { * @return product of `multiplicand` by `multiplier` */ public Long multiply(long multiplicand, long multiplier) { - return null; + Long answer = multiplicand * multiplier; + return answer; } /** @@ -193,7 +212,8 @@ public Long multiply(long multiplicand, long multiplier) { * @return product of `multiplicand` by `multiplier` */ public Short multiply(short multiplicand, short multiplier) { - return null; + Integer answer = multiplicand * multiplier; + return answer.shortValue(); } /** * @param multiplicand value to be multiplied @@ -201,7 +221,8 @@ public Short multiply(short multiplicand, short multiplier) { * @return product of `multiplicand` by `multiplier` */ public Byte multiply(byte multiplicand, byte multiplier) { - return null; + Integer answer = multiplicand * multiplier; + return answer.byteValue(); } /** @@ -210,7 +231,8 @@ public Byte multiply(byte multiplicand, byte multiplier) { * @return product of `multiplicand` by `multiplier` */ public Float multiply(float multiplicand, float multiplier) { - return null; + Float answer = multiplicand * multiplier; + return answer; } /** @@ -219,6 +241,7 @@ public Float multiply(float multiplicand, float multiplier) { * @return product of `multiplicand` by `multiplier` */ public Double multiply(double multiplicand, double multiplier) { - return null; + Double answer = multiplicand * multiplier; + return answer; } } 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..ad1de46 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,7 +10,11 @@ public class PredicateUtilities { * @return true if `x` is greater than `y` */ public Boolean isGreaterThan(int x, int y) { - return null; + if(x > y) { + return true; + } + else { return false; } + } /** @@ -19,7 +23,10 @@ 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 +35,11 @@ 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 +48,10 @@ 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 +59,19 @@ public Boolean isLessThanOrEqualTo(int x, int y) { * @return true */ public Boolean returnTrue() { - return null; + if(true) { + return true; + } + else { return false; } } /** * @return false */ public Boolean returnFalse() { - return null; + if (false) { + } + 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 2f776a9..af2cea3 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,7 @@ public class StringUtilities { * @return `Hello World` as a string */ public static String getHelloWorld() { - return null; + return "Hello World"; } /** @@ -17,7 +17,8 @@ public static String getHelloWorld() { * @return the concatenation of two strings, `firstSegment`, and `secondSegment` */ public static String concatenation(String firstSegment, String secondSegment){ - return null; + String result = firstSegment + secondSegment; + return result; } /** @@ -26,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; + String result = firstSegment + secondSegment; + return result; } /** @@ -34,7 +36,8 @@ public static String concatenation(int firstSegment, String secondSegment){ * @return the first 3 characters of `input` */ public static String getPrefix(String input){ - return null; + String result = input.substring(0,3); + return result; } /** @@ -42,7 +45,9 @@ public static String getPrefix(String input){ * @return the last 3 characters of `input` */ public static String getSuffix(String input){ - return null; + String wordInput = input; + int length = input.length(); + return wordInput.substring(length - 3); } /** @@ -51,7 +56,7 @@ 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; + return inputValue == comparableValue; } /** @@ -59,15 +64,25 @@ public static Boolean compareTwoStrings(String inputValue, String comparableValu * @return the middle character of `inputValue` */ public static Character getMiddleCharacter(String inputValue){ - return null; - } + int inputLength = inputValue.length(); + int inputHalf; + if (inputLength % 2 == 0) { + inputHalf = inputLength / 2 - 1; + } + else { + inputHalf = inputLength / 2; + } + return inputValue.charAt(inputHalf); + } + /** * @param spaceDelimitedString a string, representative of a sentence, containing spaces * @return the first sequence of characters */ public static String getFirstWord(String spaceDelimitedString){ - return null; + String allWords[] = spaceDelimitedString.split(" "); + return allWords[0]; } /** @@ -75,7 +90,8 @@ 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 allWords[] = spaceDelimitedString.split(" "); + return allWords[1]; } /** @@ -83,6 +99,7 @@ public static String getSecondWord(String spaceDelimitedString){ * @return an identical string with characters in reverse order. */ public static String reverse(String stringToReverse){ - return null; + StringBuilder string = new StringBuilder(stringToReverse); + return string.reverse().toString(); } } 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!"); } }