Kate Moore пре 6 година
родитељ
комит
97a49b4de4
3 измењених фајлова са 39 додато и 10 уклоњено
  1. 18
    2
      LoopFun.java
  2. 9
    5
      MathUtilities.java
  3. 12
    3
      StringUtilities.java

+ 18
- 2
LoopFun.java Прегледај датотеку

@@ -8,7 +8,11 @@ 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 fact = 1;
12
+          for(int i = 1; i <= number; i++) {
13
+              fact *= i;
14
+          }
15
+          return fact;
12 16
       }
13 17
 
14 18
       /**
@@ -19,7 +23,13 @@ public class LoopFun
19 23
        * @return Upper case string of the first letter of each word
20 24
        */
21 25
       public String acronym(String phrase) {
22
-          return null;
26
+          String acro = "";
27
+          String[] newPhrase = phrase.split(" ");
28
+          for (int i = 0; i < newPhrase.length; i++) {
29
+              acro += newPhrase[i].substring(0,1);
30
+            }
31
+          
32
+          return acro.toUpperCase();
23 33
       }
24 34
 
25 35
       /**
@@ -35,6 +45,12 @@ 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) {
48
+          //String newWord = "";
49
+          //String[] letters = word.split("");
50
+          //for (int i = 0; i <letters.length; i++) {
51
+            //  newWord += letters[i]
52
+              
53
+          //}
38 54
           return null;
39 55
       }
40 56
 }

+ 9
- 5
MathUtilities.java Прегледај датотеку

@@ -6,7 +6,7 @@ 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
+      return num1 + num2;
10 10
   }
11 11
 
12 12
   /**
@@ -16,7 +16,7 @@ public class MathUtilities{
16 16
    * @return the sum of the two numbers
17 17
    */
18 18
   public double add(double num1, double num2){
19
-      return -1;
19
+      return num1 + num2;
20 20
   }
21 21
 
22 22
   /**
@@ -25,7 +25,7 @@ public class MathUtilities{
25 25
    * @return the half of the number in double
26 26
    */
27 27
   public double half(int number) {
28
-      return -1;
28
+      return number / 2.0;
29 29
   }
30 30
 
31 31
   /**
@@ -34,7 +34,11 @@ public class MathUtilities{
34 34
    * @return true if the number is odd, false if it is even
35 35
    */
36 36
   public boolean isOdd(int number){
37
-      return false;
37
+      if (number % 2 != 0) {
38
+          return true;
39
+      } else {
40
+          return false;
41
+        }
38 42
   }
39 43
 
40 44
 
@@ -44,7 +48,7 @@ public class MathUtilities{
44 48
    * @return the result of the number multiply by itself
45 49
    */
46 50
   public int square(int number) {
47
-      return -1;
51
+      return number * number;
48 52
   }
49 53
 
50 54
 }

+ 12
- 3
StringUtilities.java Прегледај датотеку

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