Преглед на файлове

Nick Satinover QuizWeek1

Nicholas Satinover преди 6 години
родител
ревизия
f58fe9f549
променени са 4 файла, в които са добавени 75 реда и са изтрити 36 реда
  1. 28
    4
      LoopFun.java
  2. 5
    5
      MathUtilities.java
  3. 15
    3
      StringUtilities.java
  4. 27
    24
      package.bluej

+ 28
- 4
LoopFun.java Целия файл

@@ -8,7 +8,12 @@ public class LoopFun
8 8
        * @return the factorial of the number
9 9
        */
10 10
       public int factorial(int number){
11
-          return -1;
11
+          int fact = 1;
12
+          for(int i = 1; i <= number; i++)
13
+          {
14
+              fact *= i;
15
+          }
16
+          return fact;
12 17
       }
13 18
 
14 19
       /**
@@ -19,13 +24,20 @@ public class LoopFun
19 24
        * @return Upper case string of the first letter of each word
20 25
        */
21 26
       public String acronym(String phrase) {
22
-          return null;
27
+          String[] strArr = phrase.split(" ");
28
+          String acronym = "";
29
+          for(int i = 0; i < strArr.length; i++)
30
+          {
31
+              String tempStr = strArr[i].substring(0, 1);
32
+              acronym = acronym.concat(tempStr.toUpperCase());
33
+          }
34
+          return acronym;
23 35
       }
24 36
 
25 37
       /**
26 38
        * To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
27 39
        * 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.
40
+       * at the end of the alphabet, it will wrap around.
29 41
        * For example:
30 42
        *  'a' => 'd'
31 43
        *  'w' => 'z'
@@ -33,8 +45,20 @@ public class LoopFun
33 45
        *  'y' => 'b'
34 46
        * @param word
35 47
        * @return the encrypted string by shifting each character by three character
48
+       * ansi 97 ('a') to 122 ('z')
36 49
        */
37 50
       public String encrypt(String word) {
38
-          return null;
51
+          char[] charArr = word.toCharArray();
52
+          for(int i = 0; i < charArr.length; i++)
53
+          {
54
+              int tempInt = ((int)charArr[i]) + 3;
55
+              if(tempInt > 122)
56
+              {
57
+                  tempInt -= 26;
58
+              }
59
+              charArr[i] = (char)tempInt;
60
+          }
61
+          String returnStr = new String(charArr);
62
+          return returnStr;
39 63
       }
40 64
 }

+ 5
- 5
MathUtilities.java Целия файл

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

+ 15
- 3
StringUtilities.java Целия файл

@@ -1,13 +1,25 @@
1 1
 public class StringUtilities {
2 2
    public Character getMiddleCharacter(String word){
3
-       return null;
3
+       char middle;
4
+       if(word.length() % 2 == 1)
5
+       {
6
+           middle = word.charAt((word.length() - 1) / 2);
7
+       }
8
+       else
9
+       {
10
+           middle = word.charAt(word.length() / 2);        
11
+       }
12
+       return middle;
4 13
    }
5 14
    
6 15
    public String removeCharacter(String value, char charToRemove){
7
-     return null;  
16
+       String strChar = Character.toString(charToRemove);
17
+       String str = value.replaceAll(strChar, "");
18
+       return str;
8 19
    }
9 20
    
10 21
    public String getLastWord(String value) {
11
-       return null;
22
+       String[] strArr = value.split(" ");
23
+       return strArr[strArr.length - 1];
12 24
    }
13 25
 }

+ 27
- 24
package.bluej Целия файл

@@ -2,26 +2,30 @@
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
-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
16
-objectbench.width=669
17
-package.divider.horizontal=0.6
18
-package.divider.vertical=0.7628294036061026
19
-package.editor.height=543
20
-package.editor.width=567
21
-package.editor.x=557
22
-package.editor.y=43
23
-package.frame.height=779
24
-package.frame.width=693
11
+editor.fx.0.height=1057
12
+editor.fx.0.width=936
13
+editor.fx.0.x=-240
14
+editor.fx.0.y=-1057
15
+editor.fx.1.height=1040
16
+editor.fx.1.width=876
17
+editor.fx.1.x=798
18
+editor.fx.1.y=-1057
19
+objectbench.height=147
20
+objectbench.width=556
21
+package.divider.horizontal=0.5692618806875632
22
+package.divider.vertical=0.8458458458458459
23
+package.editor.height=838
24
+package.editor.width=883
25
+package.editor.x=-240
26
+package.editor.y=-1057
27
+package.frame.height=1057
28
+package.frame.width=1009
25 29
 package.numDependencies=3
26 30
 package.numTargets=6
27 31
 package.showExtends=true
@@ -40,20 +44,19 @@ target1.width=110
40 44
 target1.x=110
41 45
 target1.y=150
42 46
 target2.height=50
43
-target2.name=BonusTest
47
+target2.name=LoopFunTest
44 48
 target2.showInterface=false
45 49
 target2.type=UnitTestTargetJunit4
46
-target2.width=80
50
+target2.width=110
47 51
 target2.x=120
48
-target2.y=270
49
-target3.association=BonusTest
52
+target2.y=360
50 53
 target3.height=50
51
-target3.name=Bonus
54
+target3.name=LoopFun
52 55
 target3.showInterface=false
53 56
 target3.type=ClassTarget
54 57
 target3.width=80
55
-target3.x=90
56
-target3.y=300
58
+target3.x=30
59
+target3.y=390
57 60
 target4.association=MathUtilitiesTest
58 61
 target4.height=50
59 62
 target4.name=MathUtilities
@@ -74,6 +77,6 @@ target6.height=50
74 77
 target6.name=MathUtilitiesTest
75 78
 target6.showInterface=false
76 79
 target6.type=UnitTestTargetJunit4
77
-target6.width=100
80
+target6.width=130
78 81
 target6.x=110
79 82
 target6.y=40