Tennessee Gibbs před 6 roky
rodič
revize
5c4d7f3557

binární
Factorial.class Zobrazit soubor


+ 5
- 0
Factorial.ctxt Zobrazit soubor

@@ -0,0 +1,5 @@
1
+#BlueJ class context
2
+comment0.target=Factorial
3
+comment1.params=value
4
+comment1.target=java.math.BigInteger\ factorialOf(java.lang.Integer)
5
+numComments=2

+ 7
- 1
Factorial.java Zobrazit soubor

@@ -6,7 +6,13 @@ import java.math.BigInteger;
6 6
 public class Factorial {
7 7
 
8 8
     public BigInteger factorialOf(Integer value){
9
-        return null;
9
+        BigInteger answer = BigInteger.valueOf(1);
10
+        for (long i = 2 ; i<= value.longValue(); i++){
11
+        
12
+        answer = answer.multiply(BigInteger.valueOf(i));
13
+    }
14
+        
15
+        return answer;
10 16
     }
11 17
 
12 18
 }

binární
FactorialTest.class Zobrazit soubor


+ 7
- 0
FactorialTest.ctxt Zobrazit soubor

@@ -0,0 +1,7 @@
1
+#BlueJ class context
2
+comment0.target=FactorialTest
3
+comment1.params=
4
+comment1.target=void\ setUp()
5
+comment2.params=
6
+comment2.target=void\ factorialOfTest()
7
+numComments=3

binární
IntegerPrinter.class Zobrazit soubor


+ 11
- 0
IntegerPrinter.ctxt Zobrazit soubor

@@ -0,0 +1,11 @@
1
+#BlueJ class context
2
+comment0.target=IntegerPrinter
3
+comment1.params=value
4
+comment1.target=java.lang.String\ printIntegerAsBinary(int)
5
+comment2.params=value
6
+comment2.target=java.lang.String\ printIntegerAsOctal(int)
7
+comment3.params=value
8
+comment3.target=java.lang.String\ printIntegerAsHexadecimal(int)
9
+comment4.params=args
10
+comment4.target=void\ main(java.lang.String[])
11
+numComments=5

+ 3
- 5
IntegerPrinter.java Zobrazit soubor

@@ -1,18 +1,16 @@
1
- 
2 1
 
3 2
 
4 3
 public class IntegerPrinter {
5 4
 
6 5
     public String printIntegerAsBinary(int value){
7
-        return null;
6
+        return Integer.toBinaryString(value);
8 7
     }
9
-
10 8
     public String printIntegerAsOctal(int value){
11
-        return null;
9
+        return Integer.toOctalString(value);
12 10
     }
13 11
 
14 12
     public String printIntegerAsHexadecimal(int value){
15
-        return null;
13
+        return Integer.toHexString(value);
16 14
     }
17 15
 
18 16
     public static void main(String[] args){

binární
IntegerPrinterTest.class Zobrazit soubor


+ 11
- 0
IntegerPrinterTest.ctxt Zobrazit soubor

@@ -0,0 +1,11 @@
1
+#BlueJ class context
2
+comment0.target=IntegerPrinterTest
3
+comment1.params=
4
+comment1.target=void\ setUp()
5
+comment2.params=
6
+comment2.target=void\ printIntegerAsBinaryTest()
7
+comment3.params=
8
+comment3.target=void\ printIntegerAsHexadecimal()
9
+comment4.params=
10
+comment4.target=void\ printIntegerAsOctalTest()
11
+numComments=5

binární
LargestInteger.class Zobrazit soubor


+ 7
- 0
LargestInteger.ctxt Zobrazit soubor

@@ -0,0 +1,7 @@
1
+#BlueJ class context
2
+comment0.target=LargestInteger
3
+comment1.params=integers
4
+comment1.target=java.lang.Integer\ findLargestNumberUsingConditional(java.lang.Integer[])
5
+comment2.params=integers
6
+comment2.target=java.lang.Integer\ findLargestNumberUsingMathMax(java.lang.Integer[])
7
+numComments=3

+ 20
- 2
LargestInteger.java Zobrazit soubor

@@ -4,10 +4,28 @@
4 4
 public class LargestInteger {
5 5
 
6 6
     public Integer findLargestNumberUsingConditional(Integer[] integers){
7
-        return null;
7
+        int large = integers[0];
8
+        
9
+        for (int i = 0; i < integers.length ; i++){
10
+        if (large < integers[i]){
11
+            large = integers[i];
12
+            
13
+            
14
+        }
15
+  
16
+    }
17
+        
18
+        
19
+        
20
+        
21
+        
22
+        return large;
8 23
     }
9 24
 
10 25
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
11
-        return null;
26
+        
27
+        
28
+        
29
+        return Math.max(integers[0], Math.max(integers[1], integers[2]));
12 30
     }
13 31
 }

binární
LargestIntegerTest.class Zobrazit soubor


+ 9
- 0
LargestIntegerTest.ctxt Zobrazit soubor

@@ -0,0 +1,9 @@
1
+#BlueJ class context
2
+comment0.target=LargestIntegerTest
3
+comment1.params=
4
+comment1.target=void\ setUp()
5
+comment2.params=
6
+comment2.target=void\ findLargestNumberUsingConditionalTest()
7
+comment3.params=
8
+comment3.target=void\ findLargestNumberUsingMathMaxTest()
9
+numComments=4

binární
NormalizeAngle.class Zobrazit soubor


+ 9
- 0
NormalizeAngle.ctxt Zobrazit soubor

@@ -0,0 +1,9 @@
1
+#BlueJ class context
2
+comment0.target=NormalizeAngle
3
+comment1.params=angle
4
+comment1.target=java.lang.Integer\ normalizeValueUsingModulo(java.lang.Integer)
5
+comment2.params=integer
6
+comment2.target=java.lang.Integer\ normalizeValueUsingFloorMod(java.lang.Integer)
7
+comment3.params=args
8
+comment3.target=void\ main(java.lang.String[])
9
+numComments=4

+ 5
- 7
NormalizeAngle.java Zobrazit soubor

@@ -1,14 +1,12 @@
1
- 
2
-
3 1
 
4 2
 public class NormalizeAngle {
5
-
6 3
     public Integer normalizeValueUsingModulo(Integer angle){
7
-        return 0;
8
-    }
9
-
4
+        
5
+          return angle %360;  
6
+        }
10 7
     public Integer normalizeValueUsingFloorMod(Integer integer){
11
-        return 0;
8
+       
9
+        return Math.floorMod(integer, 360);
12 10
     }
13 11
 
14 12
     public static void main(String[] args){

binární
NormalizeAngleTest.class Zobrazit soubor


+ 9
- 0
NormalizeAngleTest.ctxt Zobrazit soubor

@@ -0,0 +1,9 @@
1
+#BlueJ class context
2
+comment0.target=NormalizeAngleTest
3
+comment1.params=
4
+comment1.target=void\ setUp()
5
+comment2.params=
6
+comment2.target=void\ normalizeValueUsingModuloTest()
7
+comment3.params=
8
+comment3.target=void\ normalizeValueUsingFloorModTest()
9
+numComments=4

binární
ShortCalculator.class Zobrazit soubor


+ 11
- 0
ShortCalculator.ctxt Zobrazit soubor

@@ -0,0 +1,11 @@
1
+#BlueJ class context
2
+comment0.target=ShortCalculator
3
+comment1.params=x\ y
4
+comment1.target=short\ add(short,\ short)
5
+comment2.params=x\ y
6
+comment2.target=short\ subtract(short,\ short)
7
+comment3.params=x\ y
8
+comment3.target=short\ multiply(short,\ short)
9
+comment4.params=x\ y
10
+comment4.target=short\ divide(short,\ short)
11
+numComments=5

+ 24
- 0
ShortCalculator.java Zobrazit soubor

@@ -2,4 +2,28 @@
2 2
 
3 3
 
4 4
 public class ShortCalculator {
5
+  public short add(short x,short y){
6
+      
7
+    return (short) (x + y);
8
+    
9
+    
10
+    } 
11
+    public short subtract(short x,short y){
12
+      
13
+    return (short) (x - y);
14
+    
15
+    
16
+    } 
17
+    public short multiply(short x,short y){
18
+      
19
+    return (short) (x * y);
20
+    
21
+    
22
+    } 
23
+    public short divide(short x,short y){
24
+      
25
+    return (short) (x / y);
26
+    
27
+    
28
+    } 
5 29
 }

binární
ShortCalculatorTest.class Zobrazit soubor


+ 20
- 0
ShortCalculatorTest.ctxt Zobrazit soubor

@@ -0,0 +1,20 @@
1
+#BlueJ class context
2
+comment0.target=ShortCalculatorTest
3
+comment0.text=\n\ The\ test\ class\ ShortCalculatorTest.\n\n\ @author\ \ (your\ name)\n\ @version\ (a\ version\ number\ or\ a\ date)\n
4
+comment1.params=
5
+comment1.target=ShortCalculatorTest()
6
+comment2.params=
7
+comment2.target=void\ setUp()
8
+comment2.text=\n\ Sets\ up\ the\ test\ fixture.\n\n\ Called\ before\ every\ test\ case\ method.\n
9
+comment3.params=
10
+comment3.target=void\ tearDown()
11
+comment3.text=\n\ Tears\ down\ the\ test\ fixture.\n\n\ Called\ after\ every\ test\ case\ method.\n
12
+comment4.params=
13
+comment4.target=void\ add()
14
+comment5.params=
15
+comment5.target=void\ subtract()
16
+comment6.params=
17
+comment6.target=void\ multiply()
18
+comment7.params=
19
+comment7.target=void\ divide()
20
+numComments=8

+ 86
- 2
ShortCalculatorTest.java Zobrazit soubor

@@ -1,5 +1,89 @@
1
- 
2 1
 
2
+import static org.junit.Assert.*;
3
+import org.junit.After;
4
+import org.junit.Before;
5
+import org.junit.Test;
3 6
 
4
-public class ShortCalculatorTest {
7
+/**
8
+ * The test class ShortCalculatorTest.
9
+ *
10
+ * @author  (your name)
11
+ * @version (a version number or a date)
12
+ */
13
+public class ShortCalculatorTest
14
+{
15
+    /**
16
+     * Default constructor for test class ShortCalculatorTest
17
+     */
18
+    ShortCalculator shortCalculator;
19
+    public ShortCalculatorTest()
20
+    {  shortCalculator = new ShortCalculator();
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {shortCalculator = new ShortCalculator();
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+
43
+    @Test
44
+    public void add(){
45
+        //:Given
46
+        short expected = 4;
47
+
48
+        //:When
49
+        short actual = shortCalculator.add((short) 2,(short) 2);
50
+
51
+
52
+        //:Then
53
+        assertEquals( expected, actual);
54
+
55
+    }
56
+    @Test
57
+    public void subtract(){
58
+        //Given
59
+        short expected = 4;
60
+
61
+        //When
62
+        short actual = shortCalculator.subtract((short) 10, (short) 6);
63
+
64
+        //Then
65
+        assertEquals( expected, actual);
66
+
67
+    }
68
+
69
+    @Test
70
+    public void multiply(){
71
+        //Given
72
+        short expected = 40;
73
+        //When
74
+        short actual = shortCalculator.multiply((short) 10, (short) 4);
75
+        //Then
76
+        assertEquals( expected, actual);
77
+
78
+    }
79
+
80
+    @Test
81
+    public void divide(){
82
+        //Given
83
+        short expected = 10;
84
+        //When
85
+        short actual = shortCalculator.divide((short) 40, (short) 4);
86
+        //Then
87
+        assertEquals( expected, actual);
88
+    }
5 89
 }

+ 41
- 37
package.bluej Zobrazit soubor

@@ -5,27 +5,30 @@ dependency1.type=UsesDependency
5 5
 dependency2.from=NormalizeAngleTest
6 6
 dependency2.to=NormalizeAngle
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=FactorialTest
9
-dependency3.to=Factorial
8
+dependency3.from=IntegerPrinterTest
9
+dependency3.to=IntegerPrinter
10 10
 dependency3.type=UsesDependency
11
-dependency4.from=IntegerPrinterTest
12
-dependency4.to=IntegerPrinter
11
+dependency4.from=FactorialTest
12
+dependency4.to=Factorial
13 13
 dependency4.type=UsesDependency
14
-editor.fx.0.height=0
15
-editor.fx.0.width=0
16
-editor.fx.0.x=0
17
-editor.fx.0.y=0
14
+dependency5.from=ShortCalculatorTest
15
+dependency5.to=ShortCalculator
16
+dependency5.type=UsesDependency
17
+editor.fx.0.height=722
18
+editor.fx.0.width=1055
19
+editor.fx.0.x=380
20
+editor.fx.0.y=43
18 21
 objectbench.height=101
19
-objectbench.width=1070
20
-package.divider.horizontal=0.6
22
+objectbench.width=745
23
+package.divider.horizontal=0.5824941905499613
21 24
 package.divider.vertical=0.837593984962406
22 25
 package.editor.height=550
23
-package.editor.width=968
24
-package.editor.x=59
25
-package.editor.y=82
26
+package.editor.width=1185
27
+package.editor.x=29
28
+package.editor.y=114
26 29
 package.frame.height=723
27
-package.frame.width=1094
28
-package.numDependencies=4
30
+package.frame.width=1311
31
+package.numDependencies=5
29 32
 package.numTargets=10
30 33
 package.showExtends=true
31 34
 package.showUses=true
@@ -40,68 +43,69 @@ target1.name=Factorial
40 43
 target1.showInterface=false
41 44
 target1.type=ClassTarget
42 45
 target1.width=80
43
-target1.x=160
44
-target1.y=10
46
+target1.x=800
47
+target1.y=20
45 48
 target10.height=50
46 49
 target10.name=IntegerPrinterTest
47 50
 target10.showInterface=false
48 51
 target10.type=UnitTestTargetJunit4
49 52
 target10.width=140
50
-target10.x=10
51
-target10.y=370
53
+target10.x=830
54
+target10.y=290
52 55
 target2.height=50
53 56
 target2.name=NormalizeAngle
54 57
 target2.showInterface=false
55 58
 target2.type=ClassTarget
56 59
 target2.width=120
57
-target2.x=70
58
-target2.y=70
60
+target2.x=180
61
+target2.y=30
59 62
 target3.height=50
60 63
 target3.name=IntegerPrinter
61 64
 target3.showInterface=false
62 65
 target3.type=ClassTarget
63 66
 target3.width=110
64
-target3.x=10
65
-target3.y=130
67
+target3.x=880
68
+target3.y=410
69
+target4.association=ShortCalculatorTest
66 70
 target4.height=50
67 71
 target4.name=ShortCalculator
68 72
 target4.showInterface=false
69 73
 target4.type=ClassTarget
70 74
 target4.width=120
71
-target4.x=130
72
-target4.y=130
75
+target4.x=70
76
+target4.y=340
73 77
 target5.height=50
74 78
 target5.name=LargestInteger
75 79
 target5.showInterface=false
76 80
 target5.type=ClassTarget
77 81
 target5.width=120
78
-target5.x=10
79
-target5.y=190
82
+target5.x=80
83
+target5.y=140
80 84
 target6.height=50
81 85
 target6.name=LargestIntegerTest
82 86
 target6.showInterface=false
83 87
 target6.type=UnitTestTargetJunit4
84 88
 target6.width=140
85
-target6.x=250
86
-target6.y=190
89
+target6.x=140
90
+target6.y=180
87 91
 target7.height=50
88 92
 target7.name=ShortCalculatorTest
89 93
 target7.showInterface=false
90
-target7.type=ClassTarget
91
-target7.width=150
92
-target7.x=10
93
-target7.y=250
94
+target7.type=UnitTestTargetJunit4
95
+target7.width=120
96
+target7.x=100
97
+target7.y=310
94 98
 target8.height=50
95 99
 target8.name=NormalizeAngleTest
96 100
 target8.showInterface=false
97 101
 target8.type=UnitTestTargetJunit4
98 102
 target8.width=150
99
-target8.x=10
100
-target8.y=310
103
+target8.x=270
104
+target8.y=40
101 105
 target9.height=50
102 106
 target9.name=FactorialTest
103 107
 target9.showInterface=false
104 108
 target9.type=UnitTestTargetJunit4
105 109
 target9.width=110
106
-target9.x=410
107
-target9.y=260
110
+target9.x=900
111
+target9.y=100