CHU1TA26 6 years ago
parent
commit
6fa5382809
2 changed files with 55 additions and 53 deletions
  1. 7
    6
      LoopFun.java
  2. 48
    47
      MathUtilities.java

+ 7
- 6
LoopFun.java View File

@@ -22,11 +22,11 @@ public class LoopFun
22 22
      * @return Upper case string of the first letter of each word
23 23
      */
24 24
     public String acronym(String phrase) {
25
-
25
+        String s ="";
26 26
         String []acronym = phrase.split(" ");
27 27
 
28 28
         for (int i = 0; i < acronym.length; i++) {
29
-            String s = acronym[i];
29
+             s = acronym[i];
30 30
             s.charAt(0);
31 31
         }
32 32
 
@@ -46,13 +46,14 @@ public class LoopFun
46 46
      * @return the encrypted string by shifting each character by three character
47 47
      */
48 48
     public String encrypt(String word) {
49
-        
49
+
50 50
         char [] encodeWord= word.toCharArray();
51
-        for (int i= 0; i <encodeWord.length(); i++){
51
+
52
+        for (int i= 0; i <encodeWord.length; i++){
52 53
             if (Character.isLetter(encodeWord[i])){
53 54
                 encodeWord[i]+=3;}
54 55
         }
55
-         
56
-        return encodeWord;
56
+
57
+        return encodeWord.toString();
57 58
     }
58 59
 }

+ 48
- 47
MathUtilities.java View File

@@ -1,54 +1,55 @@
1 1
 public class MathUtilities{
2
-  /**
3
-   * Add two number together
4
-   * @param num1 first number
5
-   * @param num2 second number
6
-   * @return the sum of the two numbers
7
-   */
8
-  public int add(int num1, int num2){
9
-      return num1+num2;
10
-  }
2
+    /**
3
+     * Add two number together
4
+     * @param num1 first number
5
+     * @param num2 second number
6
+     * @return the sum of the two numbers
7
+     */
8
+    public int add(int num1, int num2){
9
+        return num1+num2;
10
+    }
11 11
 
12
-  /**
13
-   * Add two number together
14
-   * @param num1 first number
15
-   * @param num2 second number
16
-   * @return the sum of the two numbers
17
-   */
18
-  public double add(double num1, double num2){
19
-      return num1 + num2;
20
-  }
12
+    /**
13
+     * Add two number together
14
+     * @param num1 first number
15
+     * @param num2 second number
16
+     * @return the sum of the two numbers
17
+     */
18
+    public double add(double num1, double num2){
19
+        return num1 + num2;
20
+    }
21 21
 
22
-  /**
23
-   * Get half the value of the number
24
-   * @param number the number given
25
-   * @return the half of the number in double
26
-   */
27
-  public double half(int number) {
28
-      double num= number/ 2;
29
-      return (double )num;
30
-  }
22
+    /**
23
+     * Get half the value of the number
24
+     * @param number the number given
25
+     * @return the half of the number in double
26
+     */
27
+    public double half(int number) {
28
+        
29
+        return number/2.0;
30
+    }
31 31
 
32
-  /**
33
-   * Determine if the number is odd
34
-   * @param number the number given
35
-   * @return true if the number is odd, false if it is even
36
-   */
37
-  public boolean isOdd(int number){
38
-    
39
-     
40
-    
41
-      return false;
42
-  }
32
+    /**
33
+     * Determine if the number is odd
34
+     * @param number the number given
35
+     * @return true if the number is odd, false if it is even
36
+     */
37
+    public boolean isOdd(int number){
38
+        if (number %2 !=0){
39
+            return true;
40
+        } else if (number %2==0){
41
+            return false;
42
+        }  
43
+        return false;
44
+    }
43 45
 
44
-
45
-  /**
46
-   * Multiply the number by itself
47
-   * @param number the number given
48
-   * @return the result of the number multiply by itself
49
-   */
50
-  public int square(int number) {
51
-      return number * number;
52
-  }
46
+    /**
47
+     * Multiply the number by itself
48
+     * @param number the number given
49
+     * @return the result of the number multiply by itself
50
+     */
51
+    public int square(int number) {
52
+        return number * number;
53
+    }
53 54
 
54 55
 }