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..904b919 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,8 +21,10 @@ 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; +} /** * @param baseValue starting value @@ -29,8 +32,11 @@ public Long add(long baseValue, long difference) { * @return sum of `baseValue` and `difference` */ public Short add(short baseValue, short difference) { - return null; - } + + + short l = (short) (baseValue + difference); + return l; +} /** * @param baseValue starting value @@ -38,8 +44,12 @@ public Short add(short baseValue, short difference) { * @return sum of `baseValue` and `difference` */ public Byte add(byte baseValue, byte difference) { - return null; - } + + + + byte v = (byte) (baseValue + difference); + return v; +} /** * @param baseValue starting value @@ -47,7 +57,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 +67,9 @@ 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,8 +78,10 @@ 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; +} /** * @param baseValue starting value @@ -74,8 +89,10 @@ 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; +} /** * @param baseValue starting value @@ -83,8 +100,11 @@ public Long subtract(long baseValue, long difference) { * @return difference between `baseValue` and `difference` */ public Short subtract(short baseValue, short difference) { - return null; - } + + + short w = (short) (baseValue - difference); + return w; +} /** * @param baseValue starting value @@ -92,8 +112,11 @@ public Short subtract(short baseValue, short difference) { * @return difference between `baseValue` and `difference` */ public Byte subtract(byte baseValue, byte difference) { - return null; - } + + + byte mordi = (byte) (baseValue - difference); + return mordi; +} /** * @param baseValue starting value @@ -101,8 +124,10 @@ 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; +} /** * @param baseValue starting value @@ -110,115 +135,147 @@ 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; +} + /** * @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) { - return null; - } + + + return dividend /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) { - return null; - } + + + return dividend /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) { - return null; + + + short div = (short) (dividend / divisor); + return div; } /** * @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) { - return null; - } + + + byte v = (byte) (dividend / divisor); + return v; +} /** * @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) { - return null; - } + + + return dividend /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) { - return null; - } + + return dividend /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) { - return null; - } + + + return multiplicand *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) { - return null; - } + + + + return multiplicand *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; + + + short e = (short) (multiplicand * multiplier); + return e; } + /** * @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) { - return null; - } + + + byte r = (byte) (multiplicand * multiplier); + return r; +} /** * @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) { - return null; - } + + return multiplicand *multiplier; +} /** * @param multiplicand value to be multiplied * @param multiplier value to multiply by * @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..71a766c 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,17 @@ 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 { + if (x < y) { + //return false; + } + } + return false; + + } /** @@ -19,7 +29,15 @@ 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 { + if (x > y) { + //return false; + } + } + return false; } /** @@ -28,7 +46,15 @@ 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{ + if (x <= y){ + + } + } + return false; } /** @@ -37,22 +63,34 @@ 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{ + if (x >= y){ + + } + } + return false; } + + /** * @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..539dff1 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,10 @@ public class StringUtilities { * @return `Hello World` as a string */ public static String getHelloWorld() { - return null; + + String words = "Hello World"; + return words; + } /** @@ -17,7 +20,9 @@ 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 +31,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 +41,9 @@ 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 +51,9 @@ 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 +62,9 @@ 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.equals(comparableValue); + } /** @@ -59,7 +72,16 @@ public static Boolean compareTwoStrings(String inputValue, String comparableValu * @return the middle character of `inputValue` */ public static Character getMiddleCharacter(String inputValue){ - return null; + + if (inputValue.length() % 2 == 0) { + ; + return inputValue.charAt(inputValue.length() / 2 - 1); // -1 pq salia o + }else + + { + return inputValue.charAt(inputValue.length() / 2); + } + } /** @@ -67,7 +89,11 @@ public static Character getMiddleCharacter(String inputValue){ * @return the first sequence of characters */ public static String getFirstWord(String spaceDelimitedString){ - return null; + + String[] name = spaceDelimitedString.split(" "); + return name[0]; + + } /** @@ -75,7 +101,11 @@ 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[] name = spaceDelimitedString.split(" "); + return name[1]; + + } /** @@ -83,6 +113,9 @@ public static String getSecondWord(String spaceDelimitedString){ * @return an identical string with characters in reverse order. */ public static String reverse(String stringToReverse){ - return null; + + return new StringBuilder(stringToReverse).reverse().toString(); + + } }