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..f45c8e5 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 @@ -10,8 +10,8 @@ public class MathUtilities { * @param difference value to add to starting value * @return sum of `baseValue` and `difference` */ - public Integer add(int baseValue, int difference) { - return null; + public Integer add(int baseValue, int difference){ + return baseValue + difference; } /** @@ -20,7 +20,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 +28,9 @@ 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) { + + return baseValue + difference; } /** @@ -38,7 +39,8 @@ public Short add(short baseValue, short difference) { * @return sum of `baseValue` and `difference` */ public Byte add(byte baseValue, byte difference) { - return null; + + return (byte) (baseValue + difference); } /** @@ -47,7 +49,8 @@ public Byte add(byte baseValue, byte difference) { * @return sum of `baseValue` and `difference` */ public Float add(float baseValue, float difference) { - return null; + + return baseValue + difference; } /** @@ -56,7 +59,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; } /** @@ -65,7 +69,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; } /** @@ -74,7 +79,8 @@ 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; } /** @@ -83,7 +89,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); } /** @@ -92,7 +99,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); } /** @@ -101,7 +109,7 @@ 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; } /** @@ -110,7 +118,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; } @@ -120,7 +129,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; } /** @@ -129,7 +139,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; } /** @@ -138,7 +149,8 @@ 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); } /** @@ -147,7 +159,8 @@ 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); } /** @@ -156,7 +169,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; } /** @@ -165,7 +179,8 @@ 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; } @@ -175,7 +190,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; } /** @@ -184,7 +200,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; } /** @@ -193,7 +210,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); } /** * @param multiplicand value to be multiplied @@ -201,7 +219,8 @@ 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); } /** @@ -210,7 +229,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; } /** @@ -219,6 +239,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/PredicateUtilities.java b/src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java index cb5f822..42f56c4 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 @@ -4,55 +4,40 @@ * Created by dan on 6/14/17. */ public class PredicateUtilities { - /** - * @param x - * @param y - * @return true if `x` is greater than `y` - */ + public Boolean isGreaterThan(int x, int y) { - return null; + + return x > y; } - /** - * @param x - * @param y - * @return true if `x` is less than `y` - */ + public Boolean isLessThan(int x, int y) { - return null; + + return x < y; } - /** - * @param x - * @param y - * @return true if `x` is greater than or equal to `y` - */ + public Boolean isGreaterThanOrEqualTo(int x, int y) { - return null; + + return x >= y; } - /** - * @param x - * @param y - * @return true if `x` is less than or equal to `y` - */ + public Boolean isLessThanOrEqualTo(int x, int y) { - return null; + + return x <= 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 2f776a9..0645fc7 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,8 @@ 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; } /** @@ -26,7 +28,9 @@ 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; + } /** @@ -34,7 +38,8 @@ 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 , 3); } /** @@ -42,7 +47,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(2, 5); } /** @@ -51,7 +57,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 == comparableValue) return true; + else return false; } /** @@ -59,7 +66,15 @@ public static Boolean compareTwoStrings(String inputValue, String comparableValu * @return the middle character of `inputValue` */ public static Character getMiddleCharacter(String inputValue){ - return null; + int x = inputValue.length(); + char ans; + if (x%2 == 0) { + ans = inputValue.charAt((x/2)-1); + } else { + ans = inputValue.charAt(x/2); + } + return ans; + } /** @@ -67,7 +82,9 @@ public static Character getMiddleCharacter(String inputValue){ * @return the first sequence of characters */ public static String getFirstWord(String spaceDelimitedString){ - return null; + String arr[] = spaceDelimitedString.split(" "); + String firstWord = arr[0]; + return firstWord; } /** @@ -75,7 +92,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 arr[] = spaceDelimitedString.split(" ", 3); + String firstWord = arr[1]; + return firstWord; } /** @@ -83,6 +102,12 @@ public static String getSecondWord(String spaceDelimitedString){ * @return an identical string with characters in reverse order. */ public static String reverse(String stringToReverse){ - return null; + String output = ""; + for (int i = stringToReverse.length() - 1; i >= 0; i--) { + output = output + stringToReverse.charAt(i); + } + + return output; } -} + } + 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); }