Lauren Green před 6 roky
rodič
revize
f7602abe94
3 změnil soubory, kde provedl 55 přidání a 11 odebrání
  1. 23
    3
      LoopFun.java
  2. 15
    5
      MathUtilities.java
  3. 17
    3
      StringUtilities.java

+ 23
- 3
LoopFun.java Zobrazit soubor

@@ -8,7 +8,12 @@ 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 answer = 1;
12
+          for (int i = number; i > 0; i--) {
13
+              answer = answer * i;
14
+          
15
+        }
16
+        return answer;
12 17
       }
13 18
 
14 19
       /**
@@ -19,7 +24,12 @@ public class LoopFun
19 24
        * @return Upper case string of the first letter of each word
20 25
        */
21 26
       public String acronym(String phrase) {
22
-          return null;
27
+          String answer = "";
28
+          for (String s : phrase.split(" ")) {
29
+              answer = answer + s.charAt(0);
30
+            }
31
+            answer = answer.toUpperCase();
32
+          return answer;
23 33
       }
24 34
 
25 35
       /**
@@ -35,6 +45,16 @@ public class LoopFun
35 45
        * @return the encrypted string by shifting each character by three character
36 46
        */
37 47
       public String encrypt(String word) {
38
-          return null;
48
+          char[] letters = "abcdefghijklmnopqrstuvwxyz".toCharArray();
49
+          char[] enc = "defghijklmnopqrstuvwxyzabc".toCharArray();
50
+          String answer = "";
51
+          int index;
52
+          
53
+          for (int i = 0; i < word.length(); i++) {
54
+            char currentLetter = word.charAt(i);
55
+            index = (new String(letters).indexOf(currentLetter));
56
+            answer = answer + (new String(enc).charAt(index));
57
+        }
58
+          return answer;
39 59
       }
40 60
 }

+ 15
- 5
MathUtilities.java Zobrazit soubor

@@ -6,7 +6,8 @@ public class MathUtilities{
6 6
    * @return the sum of the two numbers
7 7
    */
8 8
   public int add(int num1, int num2){
9
-      return -1;
9
+      int answer = num1 + num2;
10
+      return answer;
10 11
   }
11 12
 
12 13
   /**
@@ -16,7 +17,8 @@ public class MathUtilities{
16 17
    * @return the sum of the two numbers
17 18
    */
18 19
   public double add(double num1, double num2){
19
-      return -1;
20
+      double answer = num1 + num2;
21
+      return answer;
20 22
   }
21 23
 
22 24
   /**
@@ -25,7 +27,8 @@ public class MathUtilities{
25 27
    * @return the half of the number in double
26 28
    */
27 29
   public double half(int number) {
28
-      return -1;
30
+      double answer = (double) number / 2;
31
+      return answer;
29 32
   }
30 33
 
31 34
   /**
@@ -34,7 +37,13 @@ public class MathUtilities{
34 37
    * @return true if the number is odd, false if it is even
35 38
    */
36 39
   public boolean isOdd(int number){
37
-      return false;
40
+      boolean answer;
41
+      if (number % 2 == 1) {
42
+          answer = true;
43
+        } else {
44
+            answer = false;
45
+        }
46
+      return answer;
38 47
   }
39 48
 
40 49
 
@@ -44,7 +53,8 @@ public class MathUtilities{
44 53
    * @return the result of the number multiply by itself
45 54
    */
46 55
   public int square(int number) {
47
-      return -1;
56
+      int answer = number * number;
57
+      return answer;
48 58
   }
49 59
 
50 60
 }

+ 17
- 3
StringUtilities.java Zobrazit soubor

@@ -1,13 +1,27 @@
1 1
 public class StringUtilities {
2 2
    public Character getMiddleCharacter(String word){
3
-       return null;
3
+       int middleIndex = word.length() / 2;
4
+       char answer = word.charAt(middleIndex);
5
+       
6
+       return answer;
4 7
    }
5 8
    
6 9
    public String removeCharacter(String value, char charToRemove){
7
-     return null;  
10
+       String answer = "";
11
+       for (int i = 0; i < value.length(); i++) {
12
+           char currentChar = value.charAt(i);
13
+           if (!(currentChar == charToRemove)) {
14
+               answer = answer + value.charAt(i);
15
+            }
16
+       
17
+    }
18
+    return answer;
8 19
    }
9 20
    
10 21
    public String getLastWord(String value) {
11
-       return null;
22
+       String answer = value.substring(value.lastIndexOf(" ") + 1);
23
+       
24
+       
25
+       return answer;
12 26
    }
13 27
 }