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..955a689 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; } /** @@ -19,8 +20,9 @@ public Integer add(int baseValue, int difference) { * @param difference value to add to starting value * @return sum of `baseValue` and `difference` */ - public Long add(long baseValue, long difference) { - return null; + public Long add(long baseValue, long difference) + { + return baseValue + difference; } /** @@ -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; + Integer total = baseValue + difference; + return total.shortValue(); } /** @@ -38,7 +41,9 @@ public Short add(short baseValue, short difference) { * @return sum of `baseValue` and `difference` */ public Byte add(byte baseValue, byte difference) { - return null; + + Integer total = baseValue + difference; + return total.byteValue(); } /** @@ -47,7 +52,7 @@ 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 +61,7 @@ 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 +70,7 @@ 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,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; } /** @@ -83,7 +88,8 @@ public Long subtract(long baseValue, long difference) { * @return difference between `baseValue` and `difference` */ public Short subtract(short baseValue, short difference) { - return null; + Integer differenceValue = baseValue - difference; + return differenceValue.shortValue(); } /** @@ -92,7 +98,8 @@ public Short subtract(short baseValue, short difference) { * @return difference between `baseValue` and `difference` */ public Byte subtract(byte baseValue, byte difference) { - return null; + Integer differenceValue = baseValue - difference; + return differenceValue.byteValue(); } /** @@ -101,7 +108,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 +117,7 @@ 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 +127,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 +137,7 @@ 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 +146,8 @@ public Long divide(long dividend, long divisor) { * @return division of `dividend` by `divisor */ public Short divide(short dividend, short divisor) { - return null; + Integer divider = dividend/divisor; + return divider.shortValue(); } /** @@ -147,7 +156,8 @@ public Short divide(short dividend, short divisor) { * @return division of `dividend` by `divisor */ public Byte divide(byte dividend, byte divisor) { - return null; + Integer divider = dividend/divisor; + return divider.byteValue(); } /** @@ -156,7 +166,7 @@ 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 +175,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; } @@ -175,7 +185,7 @@ 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 +194,7 @@ 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 +203,8 @@ public Long multiply(long multiplicand, long multiplier) { * @return product of `multiplicand` by `multiplier` */ public Short multiply(short multiplicand, short multiplier) { - return null; + Integer multipliedValue = multiplicand * multiplier; + return multipliedValue.shortValue(); } /** * @param multiplicand value to be multiplied @@ -201,7 +212,9 @@ public Short multiply(short multiplicand, short multiplier) { * @return product of `multiplicand` by `multiplier` */ public Byte multiply(byte multiplicand, byte multiplier) { - return null; + + Integer multipliedValue = multiplicand * multiplier; + return multipliedValue.byteValue(); } /** @@ -210,7 +223,7 @@ 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 +232,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..14efbdc 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,13 @@ public class PredicateUtilities { * @return true if `x` is greater than `y` */ public Boolean isGreaterThan(int x, int y) { - return null; + Boolean isGreater = false; + if(x > y) + { + isGreater = true; + } + + return isGreater; } /** @@ -19,7 +25,13 @@ public Boolean isGreaterThan(int x, int y) { * @return true if `x` is less than `y` */ public Boolean isLessThan(int x, int y) { - return null; + Boolean isLesser = false; + if(x < y) + { + isLesser = true; + } + + return isLesser; } /** @@ -28,7 +40,13 @@ 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; + Boolean isGreaterThanOrEqual = false; + if(x >= y) + { + isGreaterThanOrEqual = true; + } + + return isGreaterThanOrEqual; } /** @@ -37,7 +55,13 @@ 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; + Boolean isLesserThanOrEqual = false; + if(x <= y) + { + isLesserThanOrEqual = true; + } + + return isLesserThanOrEqual; } @@ -45,14 +69,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..8af3db3 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; } /** @@ -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,3); } /** @@ -42,7 +45,7 @@ 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()-3); } /** @@ -51,7 +54,11 @@ 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; + Boolean compare = false; + if(inputValue.equals(comparableValue)) { + compare = true; + } + return compare; } /** @@ -59,7 +66,19 @@ public static Boolean compareTwoStrings(String inputValue, String comparableValu * @return the middle character of `inputValue` */ public static Character getMiddleCharacter(String inputValue){ - return null; + int len = inputValue.length(); + char ch; + if(len%2==0) + { + ch=inputValue.charAt((len/2)-1); + } + else + { + ch = inputValue.charAt(len/2); + } + + return ch; + } /** @@ -67,7 +86,11 @@ public static Character getMiddleCharacter(String inputValue){ * @return the first sequence of characters */ public static String getFirstWord(String spaceDelimitedString){ - return null; +// int i = spaceDelimitedString.indexOf(' '); +// String word = spaceDelimitedString.substring(0, i); +// return word; + String[] sp = spaceDelimitedString.split(" "); + return sp[0]; } /** @@ -75,7 +98,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[] sp = spaceDelimitedString.split(" "); + return sp[1]; } /** @@ -83,6 +107,8 @@ public static String getSecondWord(String spaceDelimitedString){ * @return an identical string with characters in reverse order. */ public static String reverse(String stringToReverse){ - return null; + StringBuilder input = new StringBuilder(); + input.append(stringToReverse); + return input.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!"); } }