Jarrett Samuels 6 years ago
parent
commit
71a454d600
3 changed files with 70 additions and 12 deletions
  1. 31
    3
      LoopFun.java
  2. 17
    5
      MathUtilities.java
  3. 22
    4
      StringUtilities.java

+ 31
- 3
LoopFun.java View File

@@ -8,7 +8,14 @@ public class LoopFun
8 8
        * @return the factorial of the number
9 9
        */
10 10
       public int factorial(int number){
11
-          return -1;
11
+          int i = number;
12
+          int factorial = 5;
13
+          
14
+          while (i > 1) {
15
+            i--;
16
+            factorial = i * factorial;
17
+        };
18
+          return factorial;
12 19
       }
13 20
 
14 21
       /**
@@ -19,7 +26,15 @@ public class LoopFun
19 26
        * @return Upper case string of the first letter of each word
20 27
        */
21 28
       public String acronym(String phrase) {
22
-          return null;
29
+          int i = 0;
30
+          String[] splitem = phrase.split("\\s+");
31
+          int length = splitem.length - 1;
32
+          String acronym = "";
33
+          
34
+          while (i < length) {
35
+          acronym += "" + splitem[i].toUpperCase();
36
+        }
37
+        return acronym;
23 38
       }
24 39
 
25 40
       /**
@@ -35,6 +50,19 @@ public class LoopFun
35 50
        * @return the encrypted string by shifting each character by three character
36 51
        */
37 52
       public String encrypt(String word) {
38
-          return null;
53
+          String decode = "";
54
+          char convert;
55
+          
56
+          char[] wurd = word.toCharArray();
57
+          
58
+          for (int i = 0; i < word.length(); i++) {
59
+              
60
+              while (Character.isLetter(wurd[i])) {
61
+                  convert = (wurd[i] + 3 - (int)'a') % 26 + (int)'a';
62
+                  decode += "" + convert;
63
+                }}
64
+                
65
+              String decoded = String.valueOf(convert);
66
+              return decoded;
39 67
       }
40 68
 }

+ 17
- 5
MathUtilities.java View File

@@ -1,3 +1,7 @@
1
+import java.util.*;
2
+
3
+import java.text.DecimalFormat;
4
+
1 5
 public class MathUtilities{
2 6
   /**
3 7
    * Add two number together
@@ -6,7 +10,8 @@ public class MathUtilities{
6 10
    * @return the sum of the two numbers
7 11
    */
8 12
   public int add(int num1, int num2){
9
-      return -1;
13
+      int solution = num1 + num2;
14
+      return solution;
10 15
   }
11 16
 
12 17
   /**
@@ -16,7 +21,8 @@ public class MathUtilities{
16 21
    * @return the sum of the two numbers
17 22
    */
18 23
   public double add(double num1, double num2){
19
-      return -1;
24
+       double solution = num1 + num2;
25
+       return solution;
20 26
   }
21 27
 
22 28
   /**
@@ -25,7 +31,11 @@ public class MathUtilities{
25 31
    * @return the half of the number in double
26 32
    */
27 33
   public double half(int number) {
28
-      return -1;
34
+      double ohokay = number / 2;
35
+      DecimalFormat solution = new DecimalFormat(".#");
36
+      String theone = solution.format(ohokay);
37
+      double answer = (double) ohokay;
38
+      return answer;
29 39
   }
30 40
 
31 41
   /**
@@ -34,7 +44,8 @@ public class MathUtilities{
34 44
    * @return true if the number is odd, false if it is even
35 45
    */
36 46
   public boolean isOdd(int number){
37
-      return false;
47
+      if ((number % 2) != 0) {
48
+                return true;} else { return false;}
38 49
   }
39 50
 
40 51
 
@@ -44,7 +55,8 @@ public class MathUtilities{
44 55
    * @return the result of the number multiply by itself
45 56
    */
46 57
   public int square(int number) {
47
-      return -1;
58
+      int solution = number * number;
59
+      return solution;
48 60
   }
49 61
 
50 62
 }

+ 22
- 4
StringUtilities.java View File

@@ -1,13 +1,31 @@
1 1
 public class StringUtilities {
2 2
    public Character getMiddleCharacter(String word){
3
-       return null;
4
-   }
3
+        if (word.length() % 2 != 0) {int length = word.length() - 1;
4
+        int middle = length / 2;
5
+        String math = String.valueOf(middle + 1);
6
+        int halfway = Integer.valueOf(math);
7
+        String thechar = word.substring(halfway - 1, halfway);
8
+        char itsthechar = thechar.charAt(0);
9
+        return itsthechar;} else {
10
+            
11
+        int length = word.length();
12
+        int middle = length / 2;
13
+        String math = String.valueOf(middle + 1);
14
+        int halfway = Integer.valueOf(math);
15
+        String thechar = word.substring(halfway - 1, halfway);
16
+        char itsthechar = thechar.charAt(0);
17
+        return itsthechar;    
18
+   }}
5 19
    
6 20
    public String removeCharacter(String value, char charToRemove){
7
-     return null;  
21
+      String thechar = String.valueOf(charToRemove);
22
+      String format = value.replaceAll(thechar,"");
23
+      return format;
8 24
    }
9 25
    
10 26
    public String getLastWord(String value) {
11
-       return null;
27
+       String[] splitem = value.split("\\s+");
28
+       int length = splitem.length;
29
+       return splitem[length-1];
12 30
    }
13 31
 }