Browse Source

Quiz crash and burn.

Jennifer Tinkler 6 years ago
parent
commit
766f19908f
3 changed files with 73 additions and 30 deletions
  1. 33
    7
      MathUtilities.java
  2. 19
    1
      StringUtilities.java
  3. 21
    22
      package.bluej

+ 33
- 7
MathUtilities.java View File

@@ -1,3 +1,10 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
1 8
 public class MathUtilities{
2 9
   /**
3 10
    * Add two number together
@@ -5,8 +12,13 @@ public class MathUtilities{
5 12
    * @param num2 second number
6 13
    * @return the sum of the two numbers
7 14
    */
15
+  
16
+  
8 17
   public int add(int num1, int num2){
9
-      return -1;
18
+      
19
+  return (num1 + num2);
20
+
21
+   
10 22
   }
11 23
 
12 24
   /**
@@ -15,8 +27,10 @@ public class MathUtilities{
15 27
    * @param num2 second number
16 28
    * @return the sum of the two numbers
17 29
    */
18
-  public double add(double num1, double num2){
19
-      return -1;
30
+  public double add(double num1, double num2){ 
31
+      
32
+      return (num1 + num2); 
33
+     
20 34
   }
21 35
 
22 36
   /**
@@ -25,7 +39,10 @@ public class MathUtilities{
25 39
    * @return the half of the number in double
26 40
    */
27 41
   public double half(int number) {
28
-      return -1;
42
+      //if either number is a double the int will be converted into a double
43
+     d = (number/2); 
44
+      
45
+      return d;
29 46
   }
30 47
 
31 48
   /**
@@ -33,10 +50,18 @@ public class MathUtilities{
33 50
    * @param number the number given
34 51
    * @return true if the number is odd, false if it is even
35 52
    */
53
+
54
+  
36 55
   public boolean isOdd(int number){
37
-      return false;
56
+      
57
+          
58
+          
59
+      if ( number % 2 == 0); return false;
60
+      
61
+     else return true;
62
+    
38 63
   }
39
-
64
+ 
40 65
 
41 66
   /**
42 67
    * Multiply the number by itself
@@ -44,7 +69,8 @@ public class MathUtilities{
44 69
    * @return the result of the number multiply by itself
45 70
    */
46 71
   public int square(int number) {
47
-      return -1;
72
+      
73
+      return (number * number);
48 74
   }
49 75
 
50 76
 }

+ 19
- 1
StringUtilities.java View File

@@ -1,9 +1,27 @@
1
+import java.util.Scanner;
2
+
1 3
 public class StringUtilities {
2 4
    public Character getMiddleCharacter(String word){
3
-       return null;
5
+       //get the middle of the string
6
+       
7
+        if (str.length() <= 2) {
8
+            
9
+         return str;
10
+      }
11
+      int beginIndex = (str.length() - 1) / 2;
12
+      
13
+      int endIndex = beginIndex + 2 - (str.length() % 2);
14
+      
15
+      return str.substring(beginIndex, endIndex);
4 16
    }
17
+       
18
+ 
19
+      
20
+ }
5 21
    
6 22
    public String removeCharacter(String value, char charToRemove){
23
+       
24
+       
7 25
      return null;  
8 26
    }
9 27
    

+ 21
- 22
package.bluej View File

@@ -2,25 +2,25 @@
2 2
 dependency1.from=StringUtilitiesTest
3 3
 dependency1.to=StringUtilities
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=BonusTest
6
-dependency2.to=Bonus
5
+dependency2.from=LoopFunTest
6
+dependency2.to=LoopFun
7 7
 dependency2.type=UsesDependency
8 8
 dependency3.from=MathUtilitiesTest
9 9
 dependency3.to=MathUtilities
10 10
 dependency3.type=UsesDependency
11 11
 editor.fx.0.height=722
12 12
 editor.fx.0.width=876
13
-editor.fx.0.x=158
14
-editor.fx.0.y=216
15
-objectbench.height=164
13
+editor.fx.0.x=-293
14
+editor.fx.0.y=-996
15
+objectbench.height=163
16 16
 objectbench.width=669
17 17
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.7628294036061026
19
-package.editor.height=543
18
+package.divider.vertical=0.7635605006954103
19
+package.editor.height=542
20 20
 package.editor.width=567
21
-package.editor.x=557
22
-package.editor.y=43
23
-package.frame.height=779
21
+package.editor.x=593
22
+package.editor.y=-1057
23
+package.frame.height=777
24 24
 package.frame.width=693
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
@@ -37,23 +37,22 @@ target1.name=StringUtilitiesTest
37 37
 target1.showInterface=false
38 38
 target1.type=UnitTestTargetJunit4
39 39
 target1.width=110
40
-target1.x=110
41
-target1.y=150
40
+target1.x=100
41
+target1.y=190
42 42
 target2.height=50
43
-target2.name=BonusTest
43
+target2.name=LoopFunTest
44 44
 target2.showInterface=false
45 45
 target2.type=UnitTestTargetJunit4
46
-target2.width=80
47
-target2.x=120
48
-target2.y=270
49
-target3.association=BonusTest
46
+target2.width=110
47
+target2.x=10
48
+target2.y=330
50 49
 target3.height=50
51
-target3.name=Bonus
50
+target3.name=LoopFun
52 51
 target3.showInterface=false
53 52
 target3.type=ClassTarget
54 53
 target3.width=80
55
-target3.x=90
56
-target3.y=300
54
+target3.x=40
55
+target3.y=390
57 56
 target4.association=MathUtilitiesTest
58 57
 target4.height=50
59 58
 target4.name=MathUtilities
@@ -68,8 +67,8 @@ target5.name=StringUtilities
68 67
 target5.showInterface=false
69 68
 target5.type=ClassTarget
70 69
 target5.width=110
71
-target5.x=80
72
-target5.y=180
70
+target5.x=70
71
+target5.y=220
73 72
 target6.height=50
74 73
 target6.name=MathUtilitiesTest
75 74
 target6.showInterface=false