alizalang 6 年之前
父節點
當前提交
aa6828a934

二進制
Factorial.class 查看文件


+ 5
- 0
Factorial.ctxt 查看文件

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

+ 6
- 6
Factorial.java 查看文件

1
- 
2
-
3
-
4
 import java.math.BigInteger;
1
 import java.math.BigInteger;
5
 
2
 
6
 public class Factorial {
3
 public class Factorial {
7
 
4
 
8
     public BigInteger factorialOf(Integer value){
5
     public BigInteger factorialOf(Integer value){
9
-        return null;
6
+        BigInteger num = new BigInteger("1");
7
+        for (long i = 1; i <= value; i++){
8
+           num = num.multiply(BigInteger.valueOf(i));
9
+        }
10
+        return num;
10
     }
11
     }
11
-
12
-}
12
+}

二進制
FactorialTest.class 查看文件


+ 7
- 0
FactorialTest.ctxt 查看文件

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 查看文件

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

二進制
IntegerPrinterTest.class 查看文件


+ 11
- 0
IntegerPrinterTest.ctxt 查看文件

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 查看文件

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

+ 11
- 5
LargestInteger.java 查看文件

1
- 
2
-
3
 
1
 
4
 public class LargestInteger {
2
 public class LargestInteger {
5
 
3
 
6
     public Integer findLargestNumberUsingConditional(Integer[] integers){
4
     public Integer findLargestNumberUsingConditional(Integer[] integers){
7
-        return null;
5
+        int largest = 0;
6
+        for (int i = 0; i < integers.length; i++){
7
+            largest = integers[i] > largest ? integers[i] : largest;
8
+        }
9
+        return largest;
8
     }
10
     }
9
 
11
 
10
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
12
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
11
-        return null;
13
+        int largest = 0;
14
+        for (int i = 0; i < integers.length; i++){
15
+            largest = Math.max(integers[i], largest);
16
+        }
17
+        return largest;
12
     }
18
     }
13
-}
19
+}

二進制
LargestIntegerTest.class 查看文件


+ 9
- 0
LargestIntegerTest.ctxt 查看文件

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 查看文件

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
- 6
NormalizeAngle.java 查看文件

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

二進制
NormalizeAngleTest.class 查看文件


+ 9
- 0
NormalizeAngleTest.ctxt 查看文件

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

二進制
RunCalculator.class 查看文件


+ 5
- 0
RunCalculator.ctxt 查看文件

1
+#BlueJ class context
2
+comment0.target=RunCalculator
3
+comment1.params=args
4
+comment1.target=void\ main(java.lang.String[])
5
+numComments=2

+ 28
- 0
RunCalculator.java 查看文件

1
+import java.util.Scanner;
2
+
3
+public class RunCalculator{
4
+    public static void main (String[] args){
5
+        ShortCalculator shortCalculator = new ShortCalculator();
6
+        Scanner in = new Scanner (System.in);
7
+
8
+        System.out.println("Enter a number between 0 and 65535");
9
+        short numberOne = in.nextShort();
10
+        while(numberOne < 0 || numberOne > 65535){
11
+            System.out.println("Enter a number between 0 and 65535");
12
+            numberOne = in.nextShort();
13
+        }
14
+
15
+        System.out.println("Enter another number between 0 and 65535");
16
+        short numberTwo = in.nextShort();
17
+        while(numberTwo < 0 || numberTwo > 65535){
18
+            System.out.println("Enter another number between 0 and 65535");
19
+            numberTwo = in.nextShort();
20
+        }
21
+
22
+        System.out.println("Sum: " + shortCalculator.sum(numberOne, numberTwo));
23
+        System.out.println("Difference: "+ shortCalculator.difference(numberOne, numberTwo));
24
+        System.out.println("Product: "+ shortCalculator.product(numberOne, numberTwo));
25
+        System.out.println("Quotient :" + shortCalculator.quotient(numberOne, numberTwo));
26
+        System.out.println("Remainder: " + shortCalculator.remainder(numberOne, numberTwo));
27
+    }
28
+}

二進制
ShortCalculator.class 查看文件


+ 13
- 0
ShortCalculator.ctxt 查看文件

1
+#BlueJ class context
2
+comment0.target=ShortCalculator
3
+comment1.params=x\ y
4
+comment1.target=short\ sum(short,\ short)
5
+comment2.params=x\ y
6
+comment2.target=short\ difference(short,\ short)
7
+comment3.params=x\ y
8
+comment3.target=short\ product(short,\ short)
9
+comment4.params=x\ y
10
+comment4.target=short\ quotient(short,\ short)
11
+comment5.params=x\ y
12
+comment5.target=short\ remainder(short,\ short)
13
+numComments=6

+ 20
- 3
ShortCalculator.java 查看文件

1
- 
1
+public class ShortCalculator {
2
 
2
 
3
+    public short sum(short x, short y){
4
+        return (short) (x + y);
5
+    }
3
 
6
 
4
-public class ShortCalculator {
5
-}
7
+    public short difference(short x, short y){
8
+        return (short) (x - y);
9
+    }
10
+
11
+    public short product(short x, short y){
12
+        return (short) (x * y);
13
+    }
14
+
15
+    public short quotient(short x, short y){
16
+        return (short) (x / y);
17
+    }
18
+
19
+    public short remainder(short x, short y){
20
+        return (short) (x % y);
21
+    }
22
+}

二進制
ShortCalculatorTest.class 查看文件


+ 15
- 0
ShortCalculatorTest.ctxt 查看文件

1
+#BlueJ class context
2
+comment0.target=ShortCalculatorTest
3
+comment1.params=
4
+comment1.target=void\ setUp()
5
+comment2.params=
6
+comment2.target=void\ sumTest()
7
+comment3.params=
8
+comment3.target=void\ differenctTest()
9
+comment4.params=
10
+comment4.target=void\ productTest()
11
+comment5.params=
12
+comment5.target=void\ quotientTest()
13
+comment6.params=
14
+comment6.target=void\ remainderTest()
15
+numComments=7

+ 62
- 2
ShortCalculatorTest.java 查看文件

1
- 
1
+import org.junit.Assert;
2
+import org.junit.Before;
3
+import org.junit.Test;
2
 
4
 
5
+public class ShortCalculatorTest
6
+{
7
+    private ShortCalculator shortCalculator;
3
 
8
 
4
-public class ShortCalculatorTest {
9
+    @Before
10
+    public void setUp(){
11
+        shortCalculator = new ShortCalculator();
12
+    }
13
+
14
+    @Test
15
+    public void sumTest(){
16
+        // :Given
17
+        short expected = 12;
18
+
19
+        // :When
20
+        short actual = shortCalculator.sum((short) 10, (short)2);
21
+
22
+        // :Then
23
+        Assert.assertEquals("The values equal 12", expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void differenctTest(){
28
+        // :Given
29
+        short expected = 8;
30
+        // :When
31
+        short actual = shortCalculator.difference((short)10, (short)2);
32
+        // :Then
33
+        Assert.assertEquals("The values equal 8", expected, actual);
34
+    }
35
+
36
+    @Test
37
+    public void productTest(){
38
+        // :Given
39
+        short expected = 20;
40
+        // :When
41
+        short actual = shortCalculator.product((short)10, (short)2);
42
+        // :Then  
43
+        Assert.assertEquals("The values equal 20", expected, actual);
44
+    }
45
+
46
+    @Test
47
+    public void quotientTest(){
48
+        // :Given
49
+        short expected = 10;
50
+        // :When
51
+        short actual = shortCalculator.quotient((short)20, (short)2);
52
+        // :Then
53
+        Assert.assertEquals("The values equal 10", expected, actual); 
54
+    }
55
+
56
+    @Test
57
+    public void remainderTest(){
58
+        // :Given
59
+        short expected = 1;
60
+        // :When
61
+        short actual = shortCalculator.remainder ((short)5, (short)2);
62
+        // :Then
63
+        Assert.assertEquals("The values equal 1", expected, actual);
64
+    }
5
 }
65
 }

+ 11
- 4
package.bluej 查看文件

16
 editor.fx.0.x=0
16
 editor.fx.0.x=0
17
 editor.fx.0.y=0
17
 editor.fx.0.y=0
18
 objectbench.height=101
18
 objectbench.height=101
19
-objectbench.width=1070
20
-package.divider.horizontal=0.6
19
+objectbench.width=637
20
+package.divider.horizontal=0.5996275605214153
21
 package.divider.vertical=0.837593984962406
21
 package.divider.vertical=0.837593984962406
22
 package.editor.height=550
22
 package.editor.height=550
23
 package.editor.width=968
23
 package.editor.width=968
26
 package.frame.height=723
26
 package.frame.height=723
27
 package.frame.width=1094
27
 package.frame.width=1094
28
 package.numDependencies=4
28
 package.numDependencies=4
29
-package.numTargets=10
29
+package.numTargets=11
30
 package.showExtends=true
30
 package.showExtends=true
31
 package.showUses=true
31
 package.showUses=true
32
 project.charset=UTF-8
32
 project.charset=UTF-8
49
 target10.width=140
49
 target10.width=140
50
 target10.x=10
50
 target10.x=10
51
 target10.y=370
51
 target10.y=370
52
+target11.height=50
53
+target11.name=RunCalculator
54
+target11.showInterface=false
55
+target11.type=ClassTarget
56
+target11.width=110
57
+target11.x=170
58
+target11.y=250
52
 target2.height=50
59
 target2.height=50
53
 target2.name=NormalizeAngle
60
 target2.name=NormalizeAngle
54
 target2.showInterface=false
61
 target2.showInterface=false
87
 target7.height=50
94
 target7.height=50
88
 target7.name=ShortCalculatorTest
95
 target7.name=ShortCalculatorTest
89
 target7.showInterface=false
96
 target7.showInterface=false
90
-target7.type=ClassTarget
97
+target7.type=UnitTestTargetJunit4
91
 target7.width=150
98
 target7.width=150
92
 target7.x=10
99
 target7.x=10
93
 target7.y=250
100
 target7.y=250