Browse Source

most methods written and passed tests

Jacob Andersen 6 years ago
parent
commit
ff4ea336c3
3 changed files with 40 additions and 10 deletions
  1. 12
    1
      LoopFun.java
  2. 5
    4
      MathUtilities.java
  3. 23
    5
      StringUtilities.java

+ 12
- 1
LoopFun.java View File

@@ -8,7 +8,13 @@ public class LoopFun
8 8
        * @return the factorial of the number
9 9
        */
10 10
       public int factorial(int number){
11
-          return -1;
11
+     
12
+    { 
13
+        if (number == 0) 
14
+          return 1; 
15
+          
16
+        return number*factorial(number-1); 
17
+    }
12 18
       }
13 19
 
14 20
       /**
@@ -19,6 +25,11 @@ public class LoopFun
19 25
        * @return Upper case string of the first letter of each word
20 26
        */
21 27
       public String acronym(String phrase) {
28
+         String newstring[] = phrase.split(" ");
29
+      
30
+         for (i=0;i<newstring.length;i++){
31
+             newstring[i].
32
+            }
22 33
           return null;
23 34
       }
24 35
 

+ 5
- 4
MathUtilities.java View File

@@ -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);
29 29
   }
30 30
 
31 31
   /**
@@ -34,6 +34,7 @@ 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
+      if (number%2==0) return true;
37 38
       return false;
38 39
   }
39 40
 
@@ -44,7 +45,7 @@ public class MathUtilities{
44 45
    * @return the result of the number multiply by itself
45 46
    */
46 47
   public int square(int number) {
47
-      return -1;
48
+      return (number*number);
48 49
   }
49 50
 
50 51
 }

+ 23
- 5
StringUtilities.java View File

@@ -1,13 +1,31 @@
1 1
 public class StringUtilities {
2 2
    public Character getMiddleCharacter(String word){
3
-       return null;
3
+       int position;
4
+       String middleChar;
5
+       position = (word.length()/2);
6
+       return (word.substring(position,position+1)).charAt(0);
4 7
    }
5 8
    
6
-   public String removeCharacter(String value, char charToRemove){
7
-     return null;  
8
-   }
9
+   public String removeCharacter(String value, char charToRemove){  
10
+     char[] chars=value.toCharArray();
11
+     String str="";
12
+     for(int i=0;i<chars.length;i++){
13
+         if (chars[i]==charToRemove) {
14
+             continue;}
15
+             else{
16
+                 str+=chars[i];
17
+                }
18
+            }
19
+return (str);
20
+}
21
+
22
+
23
+
24
+
9 25
    
10 26
    public String getLastWord(String value) {
11
-       return null;
27
+       
28
+       String strArr[] = value.split(" ");
29
+       return strArr[strArr.length-1];
12 30
    }
13 31
 }