瀏覽代碼

lab update

Yauheni Papko 6 年之前
父節點
當前提交
84dd7bbdd9

二進制
Factorial.class 查看文件


+ 5
- 0
Factorial.ctxt 查看文件

@@ -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

+ 16
- 3
Factorial.java 查看文件

@@ -1,4 +1,3 @@
1
- 
2 1
 
3 2
 
4 3
 import java.math.BigInteger;
@@ -6,7 +5,21 @@ import java.math.BigInteger;
6 5
 public class Factorial {
7 6
 
8 7
     public BigInteger factorialOf(Integer value){
9
-        return null;
8
+        BigInteger factorialValue = BigInteger.valueOf(1);
9
+        for (int i=1;i<=value;i++) {
10
+            factorialValue = factorialValue.multiply(BigInteger.valueOf(i));
11
+        }
12
+        return factorialValue;
10 13
     }
11
-
14
+    
15
+    /* Overflow
16
+    public String factorialOf1000(){
17
+        int value = 1000;
18
+        BigInteger factorialValue = new BigInteger("1");
19
+        for (int i=1;i<=value;i++) {
20
+            factorialValue = factorialValue.multiply(new BigInteger(i + ""));
21
+        }
22
+        return factorialValue.toString();
23
+    }
24
+    */
12 25
 }

二進制
FactorialTest.class 查看文件


+ 7
- 0
FactorialTest.ctxt 查看文件

@@ -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

二進制
IntegerPrinter.class 查看文件


+ 11
- 0
IntegerPrinter.ctxt 查看文件

@@ -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
- 3
IntegerPrinter.java 查看文件

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

二進制
IntegerPrinterTest.class 查看文件


+ 11
- 0
IntegerPrinterTest.ctxt 查看文件

@@ -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

二進制
LargestInteger.class 查看文件


+ 7
- 0
LargestInteger.ctxt 查看文件

@@ -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

+ 12
- 3
LargestInteger.java 查看文件

@@ -1,13 +1,22 @@
1
- 
2 1
 
3 2
 
4 3
 public class LargestInteger {
5 4
 
6 5
     public Integer findLargestNumberUsingConditional(Integer[] integers){
7
-        return null;
6
+        int largestInt=0;
7
+        if ((integers[0] > integers[1]) && (integers[0] > integers[2])){
8
+            largestInt = integers[0];
9
+        } else if ((integers[1] > integers[0]) && (integers[1] > integers[2])){
10
+            largestInt = integers[1];
11
+        } else if ((integers[2] > integers[0]) && (integers[2] > integers[1])){
12
+            largestInt = integers[2];
13
+        }
14
+        return largestInt;
8 15
     }
9 16
 
10 17
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
11
-        return null;
18
+        int tempLargest = Math.max(integers[0], integers[1]);
19
+        int largestInt = Math.max (tempLargest, integers[2]);
20
+        return largestInt;
12 21
     }
13 22
 }

二進制
LargestIntegerTest.class 查看文件


+ 9
- 0
LargestIntegerTest.ctxt 查看文件

@@ -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

二進制
NormalizeAngle.class 查看文件


+ 9
- 0
NormalizeAngle.ctxt 查看文件

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

+ 4
- 4
NormalizeAngle.java 查看文件

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

二進制
NormalizeAngleTest.class 查看文件


+ 9
- 0
NormalizeAngleTest.ctxt 查看文件

@@ -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

二進制
ShortCalculator.class 查看文件


+ 13
- 0
ShortCalculator.ctxt 查看文件

@@ -0,0 +1,13 @@
1
+#BlueJ class context
2
+comment0.target=ShortCalculator
3
+comment1.params=x\ y
4
+comment1.target=short\ shortSum(short,\ short)
5
+comment2.params=x\ y
6
+comment2.target=short\ shortDifference(short,\ short)
7
+comment3.params=x\ y
8
+comment3.target=short\ shortProduct(short,\ short)
9
+comment4.params=x\ y
10
+comment4.target=short\ shortQuotient(short,\ short)
11
+comment5.params=x\ y
12
+comment5.target=short\ shortRemainder(short,\ short)
13
+numComments=6

+ 18
- 1
ShortCalculator.java 查看文件

@@ -1,5 +1,22 @@
1 1
  
2 2
 
3 3
 
4
-public class ShortCalculator {
4
+public class ShortCalculator{
5
+    public short shortSum(short x, short y){
6
+        return (short)(x+y);
7
+    }
8
+        public short shortDifference(short x, short y){
9
+        return (short)(x-y);
10
+    }
11
+        public short shortProduct(short x, short y){
12
+        return (short)(x*y);
13
+    }
14
+        public short shortQuotient(short x, short y){
15
+        return (short)(x/y);
16
+    }
17
+        public short shortRemainder(short x, short y){
18
+        return (short)(x%y);
19
+    }
20
+    
5 21
 }
22
+

二進制
ShortCalculatorTest.class 查看文件


+ 5
- 0
ShortCalculatorTest.ctxt 查看文件

@@ -0,0 +1,5 @@
1
+#BlueJ class context
2
+comment0.target=ShortCalculatorTest
3
+comment1.params=
4
+comment1.target=void\ shortSumTest()
5
+numComments=2

+ 11
- 1
ShortCalculatorTest.java 查看文件

@@ -1,5 +1,15 @@
1
- 
1
+import org.junit.Assert;
2
+import org.junit.After;
3
+import org.junit.Before;
4
+import org.junit.Test; 
2 5
 
3 6
 
4 7
 public class ShortCalculatorTest {
8
+    
9
+    @Test
10
+    public void shortSumTest(){
11
+        ShortCalculator calc = new ShortCalculator();
12
+        short x = calc.shortSum((short)23,(short)45);
13
+        Assert.assertEquals("68", x);
14
+    }
5 15
 }

+ 28
- 25
package.bluej 查看文件

@@ -11,21 +11,24 @@ dependency3.type=UsesDependency
11 11
 dependency4.from=IntegerPrinterTest
12 12
 dependency4.to=IntegerPrinter
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
18
-objectbench.height=101
19
-objectbench.width=1070
20
-package.divider.horizontal=0.6
21
-package.divider.vertical=0.837593984962406
22
-package.editor.height=550
14
+dependency5.from=ShortCalculatorTest
15
+dependency5.to=ShortCalculator
16
+dependency5.type=UsesDependency
17
+editor.fx.0.height=722
18
+editor.fx.0.width=800
19
+editor.fx.0.x=591
20
+editor.fx.0.y=30
21
+objectbench.height=227
22
+objectbench.width=608
23
+package.divider.horizontal=0.5726256983240223
24
+package.divider.vertical=0.6481203007518797
25
+package.editor.height=424
23 26
 package.editor.width=968
24
-package.editor.x=59
25
-package.editor.y=82
27
+package.editor.x=374
28
+package.editor.y=177
26 29
 package.frame.height=723
27 30
 package.frame.width=1094
28
-package.numDependencies=4
31
+package.numDependencies=5
29 32
 package.numTargets=10
30 33
 package.showExtends=true
31 34
 package.showUses=true
@@ -54,8 +57,8 @@ 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=560
61
+target2.y=60
59 62
 target3.height=50
60 63
 target3.name=IntegerPrinter
61 64
 target3.showInterface=false
@@ -68,36 +71,36 @@ target4.name=ShortCalculator
68 71
 target4.showInterface=false
69 72
 target4.type=ClassTarget
70 73
 target4.width=120
71
-target4.x=130
72
-target4.y=130
74
+target4.x=680
75
+target4.y=340
73 76
 target5.height=50
74 77
 target5.name=LargestInteger
75 78
 target5.showInterface=false
76 79
 target5.type=ClassTarget
77 80
 target5.width=120
78
-target5.x=10
79
-target5.y=190
81
+target5.x=280
82
+target5.y=80
80 83
 target6.height=50
81 84
 target6.name=LargestIntegerTest
82 85
 target6.showInterface=false
83 86
 target6.type=UnitTestTargetJunit4
84 87
 target6.width=140
85
-target6.x=250
86
-target6.y=190
88
+target6.x=230
89
+target6.y=180
87 90
 target7.height=50
88 91
 target7.name=ShortCalculatorTest
89 92
 target7.showInterface=false
90
-target7.type=ClassTarget
93
+target7.type=UnitTestTargetJunit4
91 94
 target7.width=150
92
-target7.x=10
93
-target7.y=250
95
+target7.x=300
96
+target7.y=340
94 97
 target8.height=50
95 98
 target8.name=NormalizeAngleTest
96 99
 target8.showInterface=false
97 100
 target8.type=UnitTestTargetJunit4
98 101
 target8.width=150
99
-target8.x=10
100
-target8.y=310
102
+target8.x=650
103
+target8.y=220
101 104
 target9.height=50
102 105
 target9.name=FactorialTest
103 106
 target9.showInterface=false