Browse Source

quizz answers

Steffon Williams 6 years ago
parent
commit
ba797dec13
3 changed files with 32 additions and 8 deletions
  1. 16
    2
      LoopFun.java
  2. 7
    3
      MathUtilities.java
  3. 9
    3
      StringUtilities.java

+ 16
- 2
LoopFun.java View File

@@ -1,3 +1,7 @@
1
+
2
+
3
+
4
+
1 5
 public class LoopFun
2 6
 {
3 7
 
@@ -8,7 +12,9 @@ public class LoopFun
8 12
        * @return the factorial of the number
9 13
        */
10 14
       public int factorial(int number){
11
-          return -1;
15
+          return ( number == 1 || number == 0) ? 1: number * factorial (number - 1);
16
+          
17
+       
12 18
       }
13 19
 
14 20
       /**
@@ -19,7 +25,15 @@ 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) {
22
-          return null;
28
+          String s [] = phrase.split("(\s)+");
29
+          
30
+          for(String values : s)
31
+          { 
32
+              charBuffer.append(values.charAt(0));
33
+            }
34
+          
35
+          String b = charBuffer.toString() ;
36
+          return b;
23 37
       }
24 38
 
25 39
       /**

+ 7
- 3
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 (int) (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 (double) (num1 + num2);
20 20
   }
21 21
 
22 22
   /**
@@ -25,7 +25,10 @@ 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
+      int a = number / 2;
29
+      double d = a;
30
+      
31
+      return d ;
29 32
   }
30 33
 
31 34
   /**
@@ -34,6 +37,7 @@ 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){
40
+      
37 41
       return false;
38 42
   }
39 43
 

+ 9
- 3
StringUtilities.java View File

@@ -1,13 +1,19 @@
1
+import java.util.*;
2
+
1 3
 public class StringUtilities {
2 4
    public Character getMiddleCharacter(String word){
3
-       return null;
5
+       return word.charAt((word.length() - 1)/2);
4 6
    }
5 7
    
6 8
    public String removeCharacter(String value, char charToRemove){
7
-     return null;  
9
+  String a = value.substring(0, value.length() - 1);
10
+  return a; 
11
+   
12
+       // return value.substring(0, value.length() -1);
8 13
    }
9 14
    
10 15
    public String getLastWord(String value) {
11
-       return null;
16
+       
17
+       return value.substring(value.lastIndexOf(" ") +1) ;
12 18
    }
13 19
 }