#39 Xcuello

Открыто
Xcuello хочет смерджить 1 коммит(ов) из Xcuello/QuizWeek1:master в master
4 измененных файлов: 89 добавлений и 68 удалений
  1. 50
    34
      LoopFun.java
  2. 9
    5
      MathUtilities.java
  3. 13
    11
      StringUtilities.java
  4. 17
    18
      package.bluej

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

1
 public class LoopFun
1
 public class LoopFun
2
 {
2
 {
3
 
3
 
4
-      /**
5
-       * Given a number, return the factorial of that number.
6
-       * For example, given 5, the factorial is 5 x 4 x 3 x 2 x 1 which should return 120.
7
-       * @param number
8
-       * @return the factorial of the number
9
-       */
10
-      public int factorial(int number){
11
-          return -1;
12
-      }
4
+    /**
5
+     * Given a number, return the factorial of that number.
6
+     * For example, given 5, the factorial is 5 x 4 x 3 x 2 x 1 which should return 120.
7
+     * @param number
8
+     * @return the factorial of the number
9
+     */
10
+    public int factorial(int number){
11
+        int factorial = 1;
12
+        int num = 6;
13
 
13
 
14
-      /**
15
-       * Given a phrase, get the acronym of that phrase. Acronym is the combination of
16
-       * the first character of each word in upper case.
17
-       * For example, given "Ruby on Rails", this method will return "ROR"
18
-       * @param phrase
19
-       * @return Upper case string of the first letter of each word
20
-       */
21
-      public String acronym(String phrase) {
22
-          return null;
23
-      }
14
+        for(int i = 1; i <= number; i++)
15
+        {
16
+            factorial *= i;
17
+        }
18
+        return factorial;
19
+    }
24
 
20
 
25
-      /**
26
-       * To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
27
-       * intended audience. This method encrypt the message by shifting the letter by 3 characters. If the character is
28
-       * at the end of the alphabet, it will wraps around.
29
-       * For example:
30
-       *  'a' => 'd'
31
-       *  'w' => 'z'
32
-       *  'x' => 'a'
33
-       *  'y' => 'b'
34
-       * @param word
35
-       * @return the encrypted string by shifting each character by three character
36
-       */
37
-      public String encrypt(String word) {
38
-          return null;
39
-      }
21
+    /**
22
+     * Given a phrase, get the acronym of that phrase. Acronym is the combination of
23
+     * the first character of each word in upper case.
24
+     * For example, given "Ruby on Rails", this method will return "ROR"
25
+     * @param phrase
26
+     * @return Upper case string of the first letter of each word
27
+     */
28
+    public String acronym(String phrase) {
29
+        
30
+        String initials = "";
31
+        
32
+        for (String s : phrase.split(" ")) {
33
+             
34
+            initials += s.charAt(0);
35
+        }
36
+        
37
+        return initials;
38
+
39
+    }
40
+
41
+    /**
42
+     * To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
43
+     * intended audience. This method encrypt the message by shifting the letter by 3 characters. If the character is
44
+     * at the end of the alphabet, it will wraps around.
45
+     * For example:
46
+     *  'a' => 'd'
47
+     *  'w' => 'z'
48
+     *  'x' => 'a'
49
+     *  'y' => 'b'
50
+     * @param word
51
+     * @return the encrypted string by shifting each character by three character
52
+     */
53
+    public String encrypt(String word) {
54
+        return null;
55
+    }
40
 }
56
 }

+ 9
- 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
+      return num1 + num2;
10
   }
10
   }
11
 
11
 
12
   /**
12
   /**
16
    * @return the sum of the two numbers
16
    * @return the sum of the two numbers
17
    */
17
    */
18
   public double add(double num1, double num2){
18
   public double add(double num1, double num2){
19
-      return -1;
19
+      return (double) (num1 + num2);
20
   }
20
   }
21
 
21
 
22
   /**
22
   /**
25
    * @return the half of the number in double
25
    * @return the half of the number in double
26
    */
26
    */
27
   public double half(int number) {
27
   public double half(int number) {
28
-      return -1;
28
+      return (double) number / 2;
29
   }
29
   }
30
 
30
 
31
   /**
31
   /**
34
    * @return true if the number is odd, false if it is even
34
    * @return true if the number is odd, false if it is even
35
    */
35
    */
36
   public boolean isOdd(int number){
36
   public boolean isOdd(int number){
37
-      return false;
37
+      if ((number % 2)==0){
38
+          return false;
39
+        } else {
40
+      return true;
38
   }
41
   }
42
+}
39
 
43
 
40
 
44
 
41
   /**
45
   /**
44
    * @return the result of the number multiply by itself
48
    * @return the result of the number multiply by itself
45
    */
49
    */
46
   public int square(int number) {
50
   public int square(int number) {
47
-      return -1;
51
+      return number * number;
48
   }
52
   }
49
 
53
 
50
 }
54
 }

+ 13
- 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
+        return word.substring(word.length()/2).charAt(0);
4
+    }
5
+
6
+    public String removeCharacter(String value, char charToRemove){
7
+
8
+        return null;
9
+    }
10
+
11
+    public String getLastWord(String value) {
12
+
13
+        return null;
14
+    }
13
 }
15
 }

+ 17
- 18
package.bluej Просмотреть файл

2
 dependency1.from=StringUtilitiesTest
2
 dependency1.from=StringUtilitiesTest
3
 dependency1.to=StringUtilities
3
 dependency1.to=StringUtilities
4
 dependency1.type=UsesDependency
4
 dependency1.type=UsesDependency
5
-dependency2.from=BonusTest
6
-dependency2.to=Bonus
5
+dependency2.from=LoopFunTest
6
+dependency2.to=LoopFun
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
 dependency3.from=MathUtilitiesTest
8
 dependency3.from=MathUtilitiesTest
9
 dependency3.to=MathUtilities
9
 dependency3.to=MathUtilities
10
 dependency3.type=UsesDependency
10
 dependency3.type=UsesDependency
11
 editor.fx.0.height=722
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
12
+editor.fx.0.width=1227
13
+editor.fx.0.x=-15
14
+editor.fx.0.y=108
15
+objectbench.height=150
16
 objectbench.width=669
16
 objectbench.width=669
17
 package.divider.horizontal=0.6
17
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.7628294036061026
19
-package.editor.height=543
18
+package.divider.vertical=0.7635542168674698
19
+package.editor.height=500
20
 package.editor.width=567
20
 package.editor.width=567
21
 package.editor.x=557
21
 package.editor.x=557
22
-package.editor.y=43
23
-package.frame.height=779
22
+package.editor.y=23
23
+package.frame.height=722
24
 package.frame.width=693
24
 package.frame.width=693
25
 package.numDependencies=3
25
 package.numDependencies=3
26
 package.numTargets=6
26
 package.numTargets=6
40
 target1.x=110
40
 target1.x=110
41
 target1.y=150
41
 target1.y=150
42
 target2.height=50
42
 target2.height=50
43
-target2.name=BonusTest
43
+target2.name=LoopFunTest
44
 target2.showInterface=false
44
 target2.showInterface=false
45
 target2.type=UnitTestTargetJunit4
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=240
50
 target3.height=50
49
 target3.height=50
51
-target3.name=Bonus
50
+target3.name=LoopFun
52
 target3.showInterface=false
51
 target3.showInterface=false
53
 target3.type=ClassTarget
52
 target3.type=ClassTarget
54
 target3.width=80
53
 target3.width=80
55
-target3.x=90
56
-target3.y=300
54
+target3.x=200
55
+target3.y=210
57
 target4.association=MathUtilitiesTest
56
 target4.association=MathUtilitiesTest
58
 target4.height=50
57
 target4.height=50
59
 target4.name=MathUtilities
58
 target4.name=MathUtilities