Brandon Defrancis před 6 roky
rodič
revize
c01712ec2b
4 změnil soubory, kde provedl 58 přidání a 25 odebrání
  1. 25
    3
      LoopFun.java
  2. 10
    5
      MathUtilities.java
  3. 10
    3
      StringUtilities.java
  4. 13
    14
      package.bluej

+ 25
- 3
LoopFun.java Zobrazit soubor

@@ -8,7 +8,11 @@ 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
+              fact = fact*i;
14
+            }
15
+          return fact;
12 16
       }
13 17
 
14 18
       /**
@@ -19,7 +23,13 @@ public class LoopFun
19 23
        * @return Upper case string of the first letter of each word
20 24
        */
21 25
       public String acronym(String phrase) {
22
-          return null;
26
+          
27
+          StringBuilder sb = new StringBuilder();
28
+          for (String s : phrase.split(" ")){
29
+              s = s.toUpperCase();
30
+              sb.append(s.charAt(0));
31
+            }
32
+            return sb.toString();
23 33
       }
24 34
 
25 35
       /**
@@ -35,6 +45,18 @@ public class LoopFun
35 45
        * @return the encrypted string by shifting each character by three character
36 46
        */
37 47
       public String encrypt(String word) {
38
-          return null;
48
+          int shift = 3;
49
+          String s = "";
50
+          int len = word.length();
51
+          for (int x = 0; x < len; x++){
52
+              char c = (char)(word.charAt(x) + shift);
53
+              if (c > 'z')
54
+                    s += (char)(word.charAt(x) - (26-shift));
55
+              else
56
+                    s += (char)(word.charAt(x) + shift);
57
+                            
58
+            }
59
+              
60
+          return s;
39 61
       }
40 62
 }

+ 10
- 5
MathUtilities.java Zobrazit soubor

@@ -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,8 +34,13 @@ 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
+      
38
+      if (number % 2 == 0){
37 39
       return false;
38
-  }
40
+  } else 
41
+      return true;
42
+      
43
+    }
39 44
 
40 45
 
41 46
   /**
@@ -44,7 +49,7 @@ public class MathUtilities{
44 49
    * @return the result of the number multiply by itself
45 50
    */
46 51
   public int square(int number) {
47
-      return -1;
52
+      return number * number;
48 53
   }
49 54
 
50 55
 }

+ 10
- 3
StringUtilities.java Zobrazit soubor

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

+ 13
- 14
package.bluej Zobrazit soubor

@@ -2,24 +2,24 @@
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
13
+editor.fx.0.x=769
14
+editor.fx.0.y=-858
15 15
 objectbench.height=164
16 16
 objectbench.width=669
17 17
 package.divider.horizontal=0.6
18 18
 package.divider.vertical=0.7628294036061026
19 19
 package.editor.height=543
20 20
 package.editor.width=567
21
-package.editor.x=557
22
-package.editor.y=43
21
+package.editor.x=38
22
+package.editor.y=-968
23 23
 package.frame.height=779
24 24
 package.frame.width=693
25 25
 package.numDependencies=3
@@ -40,20 +40,19 @@ target1.width=110
40 40
 target1.x=110
41 41
 target1.y=150
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=290
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=200
55
+target3.y=210
57 56
 target4.association=MathUtilitiesTest
58 57
 target4.height=50
59 58
 target4.name=MathUtilities