Michelle DiMarino 8 лет назад
Родитель
Сommit
dfd98eda5c
7 измененных файлов: 73 добавлений и 41 удалений
  1. 18
    3
      LoopFun.java
  2. 2
    0
      LoopFunTest.java
  3. 14
    5
      MathUtilities.java
  4. 2
    0
      MathUtilitiesTest.java
  5. 17
    3
      StringUtilities.java
  6. 2
    0
      StringUtilitiesTest.java
  7. 18
    30
      package.bluej

+ 18
- 3
LoopFun.java Просмотреть файл

1
+package QuizWeek1;
2
+
1
 public class LoopFun
3
 public class LoopFun
2
 {
4
 {
3
 
5
 
7
        * @param number
9
        * @param number
8
        * @return the factorial of the number
10
        * @return the factorial of the number
9
        */
11
        */
10
-      public int factorial(int number){
11
-          return -1;
12
+      public int factorial(int number){ 
13
+         int factorial = 0; 
14
+         int i = 0;
15
+          while (i <= number){
16
+              i*=i;
17
+              i++;
18
+              
19
+            }
20
+          return factorial;
12
       }
21
       }
13
 
22
 
14
       /**
23
       /**
19
        * @return Upper case string of the first letter of each word
28
        * @return Upper case string of the first letter of each word
20
        */
29
        */
21
       public String acronym(String phrase) {
30
       public String acronym(String phrase) {
22
-          return null;
31
+          int spaceIndex = phrase.indexOf(" ");
32
+          char acro = phrase.charAt(spaceIndex+1);
33
+          for (int i = 1; i < phrase.length(); i++){
34
+              acro = Character.toUpperCase(phrase.charAt(spaceIndex+1));
35
+            }
36
+          
37
+          return Character.toUpperCase(phrase.charAt(0)) + Character.toString(acro);
23
       }
38
       }
24
 
39
 
25
       /**
40
       /**

+ 2
- 0
LoopFunTest.java Просмотреть файл

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

+ 14
- 5
MathUtilities.java Просмотреть файл

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

+ 2
- 0
MathUtilitiesTest.java Просмотреть файл

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

+ 17
- 3
StringUtilities.java Просмотреть файл

1
+package QuizWeek1;
2
+
1
 public class StringUtilities {
3
 public class StringUtilities {
2
    public Character getMiddleCharacter(String word){
4
    public Character getMiddleCharacter(String word){
3
-       return null;
5
+       int middleChar;
6
+        if ((word.length()/2)%2 == 0){
7
+            middleChar = word.length()/2+1;
8
+            
9
+        }else{
10
+            middleChar = Math.round(word.length()/2);   
11
+            
12
+        }
13
+        return word.charAt(middleChar);
14
+       
4
    }
15
    }
5
    
16
    
6
    public String removeCharacter(String value, char charToRemove){
17
    public String removeCharacter(String value, char charToRemove){
7
-     return null;  
18
+     int removeChar = value.indexOf(charToRemove);      
19
+     return value.substring(0,removeChar) + value.substring(removeChar+1); 
8
    }
20
    }
9
    
21
    
10
    public String getLastWord(String value) {
22
    public String getLastWord(String value) {
11
-       return null;
23
+       int indexLastWord = value.lastIndexOf(" ");
24
+        
25
+       return value.substring(indexLastWord+1);
12
    }
26
    }
13
 }
27
 }

+ 2
- 0
StringUtilitiesTest.java Просмотреть файл

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

+ 18
- 30
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
7
-dependency2.type=UsesDependency
8
-dependency3.from=MathUtilitiesTest
9
-dependency3.to=MathUtilities
10
-dependency3.type=UsesDependency
11
-editor.fx.0.height=722
12
-editor.fx.0.width=876
13
-editor.fx.0.x=158
14
-editor.fx.0.y=216
15
-objectbench.height=164
5
+objectbench.height=147
16
 objectbench.width=669
6
 objectbench.width=669
17
 package.divider.horizontal=0.6
7
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.7628294036061026
19
-package.editor.height=543
8
+package.divider.vertical=0.7634408602150538
9
+package.editor.height=490
20
 package.editor.width=567
10
 package.editor.width=567
21
 package.editor.x=557
11
 package.editor.x=557
22
-package.editor.y=43
23
-package.frame.height=779
12
+package.editor.y=23
13
+package.frame.height=709
24
 package.frame.width=693
14
 package.frame.width=693
25
-package.numDependencies=3
15
+package.numDependencies=1
26
 package.numTargets=6
16
 package.numTargets=6
27
 package.showExtends=true
17
 package.showExtends=true
28
 package.showUses=true
18
 package.showUses=true
29
-project.charset=UTF-8
30
 readme.height=58
19
 readme.height=58
31
 readme.name=@README
20
 readme.name=@README
32
 readme.width=47
21
 readme.width=47
33
 readme.x=10
22
 readme.x=10
34
 readme.y=10
23
 readme.y=10
35
 target1.height=50
24
 target1.height=50
36
-target1.name=StringUtilitiesTest
25
+target1.name=LoopFunTest
37
 target1.showInterface=false
26
 target1.showInterface=false
38
 target1.type=UnitTestTargetJunit4
27
 target1.type=UnitTestTargetJunit4
39
 target1.width=110
28
 target1.width=110
40
-target1.x=110
41
-target1.y=150
29
+target1.x=10
30
+target1.y=240
42
 target2.height=50
31
 target2.height=50
43
-target2.name=BonusTest
32
+target2.name=StringUtilitiesTest
44
 target2.showInterface=false
33
 target2.showInterface=false
45
 target2.type=UnitTestTargetJunit4
34
 target2.type=UnitTestTargetJunit4
46
-target2.width=80
47
-target2.x=120
48
-target2.y=270
49
-target3.association=BonusTest
35
+target2.width=110
36
+target2.x=110
37
+target2.y=150
50
 target3.height=50
38
 target3.height=50
51
-target3.name=Bonus
39
+target3.name=LoopFun
52
 target3.showInterface=false
40
 target3.showInterface=false
53
 target3.type=ClassTarget
41
 target3.type=ClassTarget
54
 target3.width=80
42
 target3.width=80
55
-target3.x=90
56
-target3.y=300
43
+target3.x=120
44
+target3.y=290
57
 target4.association=MathUtilitiesTest
45
 target4.association=MathUtilitiesTest
58
 target4.height=50
46
 target4.height=50
59
 target4.name=MathUtilities
47
 target4.name=MathUtilities