De'Jon Johnson 6 年之前
父節點
當前提交
5e8eb22c2f
共有 4 個檔案被更改,包括 49 行新增35 行删除
  1. 1
    1
      LoopFun.java
  2. 16
    5
      MathUtilities.java
  3. 18
    11
      StringUtilities.java
  4. 14
    18
      package.bluej

+ 1
- 1
LoopFun.java 查看文件

8
        * @return the factorial of the number
8
        * @return the factorial of the number
9
        */
9
        */
10
       public int factorial(int number){
10
       public int factorial(int number){
11
-          return -1;
11
+         return -1;
12
       }
12
       }
13
 
13
 
14
       /**
14
       /**

+ 16
- 5
MathUtilities.java 查看文件

6
    * @return the sum of the two numbers
6
    * @return the sum of the two numbers
7
    */
7
    */
8
   public int add(int num1, int num2){
8
   public int add(int num1, int num2){
9
-      return -1;
9
+      int number = (num1 + num2);
10
+      return number;
11
+      
12
+      
10
   }
13
   }
11
 
14
 
12
   /**
15
   /**
16
    * @return the sum of the two numbers
19
    * @return the sum of the two numbers
17
    */
20
    */
18
   public double add(double num1, double num2){
21
   public double add(double num1, double num2){
19
-      return -1;
22
+      double stuff = (num1 + num2);
23
+      return stuff;
20
   }
24
   }
21
 
25
 
22
   /**
26
   /**
25
    * @return the half of the number in double
29
    * @return the half of the number in double
26
    */
30
    */
27
   public double half(int number) {
31
   public double half(int number) {
28
-      return -1;
32
+     double answer = (double)(number/2);
33
+     return answer;
34
+      
29
   }
35
   }
30
 
36
 
31
   /**
37
   /**
34
    * @return true if the number is odd, false if it is even
40
    * @return true if the number is odd, false if it is even
35
    */
41
    */
36
   public boolean isOdd(int number){
42
   public boolean isOdd(int number){
37
-      return false;
43
+        if(number % 2 != 0){
44
+          return true;
45
+        } else{
46
+        return false; 
47
+        }
38
   }
48
   }
39
 
49
 
40
 
50
 
44
    * @return the result of the number multiply by itself
54
    * @return the result of the number multiply by itself
45
    */
55
    */
46
   public int square(int number) {
56
   public int square(int number) {
47
-      return -1;
57
+      return (number*number);
58
+      
48
   }
59
   }
49
 
60
 
50
 }
61
 }

+ 18
- 11
StringUtilities.java 查看文件

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

+ 14
- 18
package.bluej 查看文件

1
 #BlueJ package file
1
 #BlueJ package file
2
-dependency1.from=StringUtilitiesTest
3
-dependency1.to=StringUtilities
2
+dependency1.from=MathUtilitiesTest
3
+dependency1.to=MathUtilities
4
 dependency1.type=UsesDependency
4
 dependency1.type=UsesDependency
5
-dependency2.from=BonusTest
6
-dependency2.to=Bonus
5
+dependency2.from=StringUtilitiesTest
6
+dependency2.to=StringUtilities
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
-dependency3.from=MathUtilitiesTest
9
-dependency3.to=MathUtilities
10
-dependency3.type=UsesDependency
11
 editor.fx.0.height=722
8
 editor.fx.0.height=722
12
 editor.fx.0.width=876
9
 editor.fx.0.width=876
13
-editor.fx.0.x=158
14
-editor.fx.0.y=216
10
+editor.fx.0.x=173
11
+editor.fx.0.y=121
15
 objectbench.height=164
12
 objectbench.height=164
16
 objectbench.width=669
13
 objectbench.width=669
17
 package.divider.horizontal=0.6
14
 package.divider.horizontal=0.6
22
 package.editor.y=43
19
 package.editor.y=43
23
 package.frame.height=779
20
 package.frame.height=779
24
 package.frame.width=693
21
 package.frame.width=693
25
-package.numDependencies=3
22
+package.numDependencies=2
26
 package.numTargets=6
23
 package.numTargets=6
27
 package.showExtends=true
24
 package.showExtends=true
28
 package.showUses=true
25
 package.showUses=true
40
 target1.x=110
37
 target1.x=110
41
 target1.y=150
38
 target1.y=150
42
 target2.height=50
39
 target2.height=50
43
-target2.name=BonusTest
40
+target2.name=LoopFunTest
44
 target2.showInterface=false
41
 target2.showInterface=false
45
 target2.type=UnitTestTargetJunit4
42
 target2.type=UnitTestTargetJunit4
46
-target2.width=80
47
-target2.x=120
48
-target2.y=270
49
-target3.association=BonusTest
43
+target2.width=110
44
+target2.x=10
45
+target2.y=240
50
 target3.height=50
46
 target3.height=50
51
-target3.name=Bonus
47
+target3.name=LoopFun
52
 target3.showInterface=false
48
 target3.showInterface=false
53
 target3.type=ClassTarget
49
 target3.type=ClassTarget
54
 target3.width=80
50
 target3.width=80
55
-target3.x=90
56
-target3.y=300
51
+target3.x=200
52
+target3.y=210
57
 target4.association=MathUtilitiesTest
53
 target4.association=MathUtilitiesTest
58
 target4.height=50
54
 target4.height=50
59
 target4.name=MathUtilities
55
 target4.name=MathUtilities