Browse Source

Refactor Complete

Kthomas 6 years ago
parent
commit
aba185069b

+ 6
- 27
src/main/java/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.java View File

1
 package com.zipcodewilmington.danny_do_better_exercises;
1
 package com.zipcodewilmington.danny_do_better_exercises;
2
 
2
 
3
 /**
3
 /**
4
- * Created by dan on 6/14/17.
4
+ * Simplified
5
  */
5
  */
6
 public class PredicateUtilities {
6
 public class PredicateUtilities {
7
 
7
 
8
     public Boolean isGreaterThan(int x, int y) {
8
     public Boolean isGreaterThan(int x, int y) {
9
-
10
-        if (x > y) {
11
-            return true;
12
-        }
13
-        else {
14
-            return false;
15
-        }
9
+        return x > y;
16
     }
10
     }
17
 
11
 
18
     public Boolean isLessThan(int x, int y) {
12
     public Boolean isLessThan(int x, int y) {
19
-        if (x < y) {
20
-            return true;
21
-        }
22
-        else {
23
-            return false;
24
-        }
13
+        return x < y;
25
     }
14
     }
26
 
15
 
27
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
16
     public Boolean isGreaterThanOrEqualTo(int x, int y) {
28
-        if (x >= y) {
29
-            return true;
30
-        }
31
-        else {
32
-            return false;
33
-        }
17
+        return x >= y;
34
     }
18
     }
35
 
19
 
36
     public Boolean isLessThanOrEqualTo(int x, int y) {
20
     public Boolean isLessThanOrEqualTo(int x, int y) {
37
-        if (x <= y) {
38
-            return true;
39
-        }
40
-        else {
41
-            return false;
42
-        }
21
+        return x <= y;
43
     }
22
     }
44
-}
23
+}

+ 6
- 15
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java View File

1
 package com.zipcodewilmington.danny_do_better_exercises;
1
 package com.zipcodewilmington.danny_do_better_exercises;
2
 
2
 
3
 /**
3
 /**
4
- * Created by dan on 6/14/17.
4
+ * Refactored
5
  */
5
  */
6
 public class StringUtilities {
6
 public class StringUtilities {
7
 
7
 
8
     public static String getHelloWorld() {
8
     public static String getHelloWorld() {
9
-
10
         return "Hello World";
9
         return "Hello World";
11
     }
10
     }
12
 
11
 
13
     public static String concatenation(String firstSegment, String secondSegment){
12
     public static String concatenation(String firstSegment, String secondSegment){
14
-
15
         return firstSegment + secondSegment;
13
         return firstSegment + secondSegment;
16
     }
14
     }
17
 
15
 
18
     public static String concatenation(int firstSegment, String secondSegment){
16
     public static String concatenation(int firstSegment, String secondSegment){
19
-
20
         return firstSegment + secondSegment;
17
         return firstSegment + secondSegment;
21
     }
18
     }
22
 
19
 
23
     public static String getPrefix(String input){
20
     public static String getPrefix(String input){
24
-
25
-        return input.substring(0,3);
21
+        return input.substring(0,3); //returns a range of characters from the string from index positions 0 - 3 (prefix)
26
     }
22
     }
27
 
23
 
28
     public static String getSuffix(String input){
24
     public static String getSuffix(String input){
29
-
30
         return input.substring(2);
25
         return input.substring(2);
31
     }
26
     }
32
 
27
 
33
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
28
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
34
-
35
         return inputValue.equals(comparableValue) ;
29
         return inputValue.equals(comparableValue) ;
36
     }
30
     }
37
 
31
 
41
         if (middleIndex % 2 == 0){
35
         if (middleIndex % 2 == 0){
42
             middleIndex = middleIndex - 1;
36
             middleIndex = middleIndex - 1;
43
         }
37
         }
44
-        char middleCharacter = inputValue.charAt(middleIndex);
45
-        return middleCharacter;
38
+
39
+        return inputValue.charAt(middleIndex);
46
     }
40
     }
47
 
41
 
48
     public static String getFirstWord(String spaceDelimitedString) {
42
     public static String getFirstWord(String spaceDelimitedString) {
56
     }
50
     }
57
 
51
 
58
     public static String reverseTheTwo(String stringToReverse){
52
     public static String reverseTheTwo(String stringToReverse){
59
-
60
-        String reverse = new StringBuffer(stringToReverse).reverse().toString();
61
-
62
-        return reverse;
53
+        return new StringBuffer(stringToReverse).reverse().toString();
63
     }
54
     }
64
-}
55
+}

+ 2
- 3
src/main/java/com/zipcodewilmington/danny_do_better_exercises/ZipcodeRocks.java View File

1
 package com.zipcodewilmington.danny_do_better_exercises;
1
 package com.zipcodewilmington.danny_do_better_exercises;
2
 
2
 
3
 /**
3
 /**
4
- * Created by leon on 2/5/18.
4
+ * Refactored
5
  */
5
  */
6
 public class ZipcodeRocks {
6
 public class ZipcodeRocks {
7
     public static void main(String[] args) {
7
     public static void main(String[] args) {
8
-
9
         System.out.println("Zipcode Rocks!");
8
         System.out.println("Zipcode Rocks!");
10
     }
9
     }
11
-}
10
+}

BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/MathUtilities.class View File


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/PredicateUtilities.class View File


BIN
target/classes/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.class View File