Simran Bhutani 6 years ago
parent
commit
b3321b9eab
6 changed files with 66 additions and 12 deletions
  1. 16
    3
      LoopFun.java
  2. 2
    0
      LoopFunTest.java
  3. 12
    5
      MathUtilities.java
  4. 2
    0
      MathUtilitiesTest.java
  5. 32
    4
      StringUtilities.java
  6. 2
    0
      StringUtilitiesTest.java

+ 16
- 3
LoopFun.java View File

@@ -1,3 +1,5 @@
1
+package QuizWeek1;
2
+
1 3
 public class LoopFun
2 4
 {
3 5
 
@@ -8,7 +10,10 @@ public class LoopFun
8 10
        * @return the factorial of the number
9 11
        */
10 12
       public int factorial(int number){
11
-          return -1;
13
+          if(number==0){
14
+          return 1;}
15
+          else{
16
+          return number*factorial(number-1);}
12 17
       }
13 18
 
14 19
       /**
@@ -19,8 +24,10 @@ 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;
23
-      }
27
+          //phrase= phrase.toLowerCase();
28
+          //String[] ph =phrase.split(" "); */
29
+          return phrase.replaceAll("[a-z ]", "").toUpperCase();
30
+        }
24 31
 
25 32
       /**
26 33
        * To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
@@ -35,6 +42,12 @@ public class LoopFun
35 42
        * @return the encrypted string by shifting each character by three character
36 43
        */
37 44
       public String encrypt(String word) {
45
+          char[] toEncode=word.toCharArray();
46
+          for(int i=0;i<toEncode.length;i++)
47
+          {
48
+            }
49
+          
38 50
           return null;
39 51
       }
52
+      
40 53
 }

+ 2
- 0
LoopFunTest.java View File

@@ -1,3 +1,5 @@
1
+package QuizWeek1;
2
+
1 3
 
2 4
 
3 5
 import static org.junit.Assert.*;

+ 12
- 5
MathUtilities.java View File

@@ -1,3 +1,5 @@
1
+package QuizWeek1;
2
+
1 3
 public class MathUtilities{
2 4
   /**
3 5
    * Add two number together
@@ -6,7 +8,7 @@ public class MathUtilities{
6 8
    * @return the sum of the two numbers
7 9
    */
8 10
   public int add(int num1, int num2){
9
-      return -1;
11
+      return (num1+num2);
10 12
   }
11 13
 
12 14
   /**
@@ -16,7 +18,7 @@ public class MathUtilities{
16 18
    * @return the sum of the two numbers
17 19
    */
18 20
   public double add(double num1, double num2){
19
-      return -1;
21
+      return (num1+num2);
20 22
   }
21 23
 
22 24
   /**
@@ -25,7 +27,7 @@ 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
+      return ( (double) number/2);
29 31
   }
30 32
 
31 33
   /**
@@ -34,7 +36,12 @@ public class MathUtilities{
34 36
    * @return true if the number is odd, false if it is even
35 37
    */
36 38
   public boolean isOdd(int number){
37
-      return false;
39
+      if(number%2 == 0)
40
+      {return  false;
41
+        }
42
+        else
43
+        {return true;}
44
+      //return false;
38 45
   }
39 46
 
40 47
 
@@ -44,7 +51,7 @@ public class MathUtilities{
44 51
    * @return the result of the number multiply by itself
45 52
    */
46 53
   public int square(int number) {
47
-      return -1;
54
+      return number*number;
48 55
   }
49 56
 
50 57
 }

+ 2
- 0
MathUtilitiesTest.java View File

@@ -1,3 +1,5 @@
1
+package QuizWeek1;
2
+
1 3
 
2 4
 
3 5
 import static org.junit.Assert.*;

+ 32
- 4
StringUtilities.java View File

@@ -1,13 +1,41 @@
1
+package QuizWeek1;
2
+
1 3
 public class StringUtilities {
2 4
    public Character getMiddleCharacter(String word){
3
-       return null;
4
-   }
5
+       
6
+        int len= word.length();
7
+        int pos;
8
+        if(len%2 == 0)
9
+        {
10
+            pos=((len/2) -1) ;
11
+            
12
+        }
13
+        else
14
+        {
15
+            pos=len/2;
16
+            
17
+        }
18
+        return word.charAt(pos);
19
+    }
20
+       
21
+   
5 22
    
6 23
    public String removeCharacter(String value, char charToRemove){
7
-     return null;  
24
+       String r="";
25
+       for(int i=0; i < value.length() ;i++)
26
+       {
27
+        if(value.charAt(i) != charToRemove)
28
+        r=r+ value.charAt(i);
29
+        }
30
+     return r; 
8 31
    }
9 32
    
10 33
    public String getLastWord(String value) {
11
-       return null;
34
+       
35
+       String[] r= value.split(" ");
36
+       String lastWord= r [r.length -1];
37
+     
38
+       return lastWord;
12 39
    }
13 40
 }
41
+   

+ 2
- 0
StringUtilitiesTest.java View File

@@ -1,3 +1,5 @@
1
+package QuizWeek1;
2
+
1 3
 import static org.junit.Assert.*;
2 4
 import org.junit.After;
3 5
 import org.junit.Before;