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..50e4f7d 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; + int sum = baseValue + difference; + return sum; } /** @@ -20,7 +21,8 @@ public Integer add(int baseValue, int difference) { * @return sum of `baseValue` and `difference` */ public Long add(long baseValue, long difference) { - return null; + long sum = baseValue + difference; + return sum; } /** @@ -29,7 +31,8 @@ public Long add(long baseValue, long difference) { * @return sum of `baseValue` and `difference` */ public Short add(short baseValue, short difference) { - return null; + short sum = (short) (baseValue + difference); + return sum; } /** @@ -38,7 +41,8 @@ public Short add(short baseValue, short difference) { * @return sum of `baseValue` and `difference` */ public Byte add(byte baseValue, byte difference) { - return null; + byte sum = (byte) (baseValue + difference); + return sum; } /** @@ -47,7 +51,8 @@ public Byte add(byte baseValue, byte difference) { * @return sum of `baseValue` and `difference` */ public Float add(float baseValue, float difference) { - return null; + float sum = baseValue + difference; + return sum; } /** @@ -56,7 +61,8 @@ public Float add(float baseValue, float difference) { * @return sum of `baseValue` and `difference` */ public Double add(double baseValue, double difference) { - return null; + double sum = baseValue + difference ; + return sum; } /** @@ -65,7 +71,8 @@ public Double add(double baseValue, double difference) { * @return difference between `baseValue` and `difference` */ public Integer subtract(int baseValue, int difference) { - return null; + int sum = baseValue - difference; + return sum; } /** @@ -74,7 +81,8 @@ public Integer subtract(int baseValue, int difference) { * @return difference between `baseValue` and `difference` */ public Long subtract(long baseValue, long difference) { - return null; + long sum = baseValue - difference; + return sum; } /** @@ -83,7 +91,8 @@ public Long subtract(long baseValue, long difference) { * @return difference between `baseValue` and `difference` */ public Short subtract(short baseValue, short difference) { - return null; + short sum = (short) (baseValue - difference); + return sum; } /** @@ -92,7 +101,8 @@ public Short subtract(short baseValue, short difference) { * @return difference between `baseValue` and `difference` */ public Byte subtract(byte baseValue, byte difference) { - return null; + byte sum = (byte) (baseValue - difference); + return sum; } /** @@ -101,7 +111,8 @@ public Byte subtract(byte baseValue, byte difference) { * @return difference between `baseValue` and `difference` */ public Float subtract(float baseValue, float difference) { - return null; + float sum = baseValue - difference; + return sum; } /** @@ -110,7 +121,8 @@ public Float subtract(float baseValue, float difference) { * @return difference between `baseValue` and `difference` */ public Double subtract(double baseValue, double difference) { - return null; + double sum = baseValue - difference; + return sum; } @@ -120,7 +132,8 @@ public Double subtract(double baseValue, double difference) { * @return division of `dividend` by `divisor */ public Integer divide(int dividend, int divisor) { - return null; + int sum = dividend/divisor; + return sum; } /** @@ -129,7 +142,8 @@ public Integer divide(int dividend, int divisor) { * @return division of `dividend` by `divisor */ public Long divide(long dividend, long divisor) { - return null; + long sum = dividend/divisor ; + return sum; } /** @@ -138,7 +152,8 @@ public Long divide(long dividend, long divisor) { * @return division of `dividend` by `divisor */ public Short divide(short dividend, short divisor) { - return null; + short sum = (short) (dividend/divisor); + return sum; } /** @@ -147,7 +162,8 @@ public Short divide(short dividend, short divisor) { * @return division of `dividend` by `divisor */ public Byte divide(byte dividend, byte divisor) { - return null; + byte sum = (byte) (dividend/divisor); + return sum; } /** @@ -156,7 +172,8 @@ public Byte divide(byte dividend, byte divisor) { * @return division of `dividend` by `divisor */ public Float divide(float dividend, float divisor) { - return null; + float sum = dividend/divisor; + return sum; } /** @@ -165,7 +182,8 @@ public Float divide(float dividend, float divisor) { * @return division of `dividend` by `divisor */ public Double divide(double dividend, double divisor) { - return null; + double sum = dividend/divisor; + return sum; } @@ -175,7 +193,8 @@ public Double divide(double dividend, double divisor) { * @return product of `multiplicand` by `multiplier` */ public Integer multiply(int multiplicand, int multiplier) { - return null; + int sum = multiplicand * multiplier; + return sum; } /** @@ -184,7 +203,8 @@ public Integer multiply(int multiplicand, int multiplier) { * @return product of `multiplicand` by `multiplier` */ public Long multiply(long multiplicand, long multiplier) { - return null; + long sum = multiplicand * multiplier; + return sum; } /** @@ -193,7 +213,8 @@ public Long multiply(long multiplicand, long multiplier) { * @return product of `multiplicand` by `multiplier` */ public Short multiply(short multiplicand, short multiplier) { - return null; + short sum = (short) (multiplicand * multiplier); + return sum; } /** * @param multiplicand value to be multiplied @@ -201,7 +222,8 @@ public Short multiply(short multiplicand, short multiplier) { * @return product of `multiplicand` by `multiplier` */ public Byte multiply(byte multiplicand, byte multiplier) { - return null; + byte sum = (byte) (multiplicand * multiplier) ; + return sum; } /** @@ -210,7 +232,8 @@ public Byte multiply(byte multiplicand, byte multiplier) { * @return product of `multiplicand` by `multiplier` */ public Float multiply(float multiplicand, float multiplier) { - return null; + float sum = multiplicand * multiplier; + return sum; } /** @@ -219,6 +242,7 @@ public Float multiply(float multiplicand, float multiplier) { * @return product of `multiplicand` by `multiplier` */ public Double multiply(double multiplicand, double multiplier) { - return null; + double sum = multiplicand * multiplier; + return sum; } } 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..94cff1e 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,10 @@ 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; + } + return false; } /** @@ -19,7 +22,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; + } + return false; } /** @@ -28,7 +34,10 @@ 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; + } + return false; } /** @@ -37,7 +46,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; + } + return false; } @@ -45,14 +57,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 2f776a9..dc15249 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; + + return firstSegment + secondSegment; } /** @@ -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; + + return firstSegment + secondSegment; } /** @@ -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; + + return input.substring(0,2); } /** @@ -42,7 +45,8 @@ public static String getPrefix(String input){ * @return the last 3 characters of `input` */ public static String getSuffix(String input){ - return null; + int index = input.length(); + return input.substring(index-3, index-1); } /** @@ -51,7 +55,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; + + return inputValue.equalsIgnoreCase(comparableValue); } /** @@ -59,7 +64,9 @@ public static Boolean compareTwoStrings(String inputValue, String comparableValu * @return the middle character of `inputValue` */ public static Character getMiddleCharacter(String inputValue){ - return null; + int stringLength = inputValue.length(); + + return inputValue.charAt((int) Math.floor(stringLength/2)); } /** @@ -67,7 +74,9 @@ public static Character getMiddleCharacter(String inputValue){ * @return the first sequence of characters */ public static String getFirstWord(String spaceDelimitedString){ - return null; + String firstWord[] = spaceDelimitedString.split(" "); + + return firstWord[0]; } /** @@ -75,7 +84,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 secondWord[] = spaceDelimitedString.split(" "); + + return secondWord[1]; } /** @@ -83,6 +94,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(); } }