浏览代码

much love for shorts

Shivam Patel 6 年前
父节点
当前提交
9cfb576f44

二进制
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

+ 8
- 1
Factorial.java 查看文件

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

二进制
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

+ 15
- 6
IntegerPrinter.java 查看文件

@@ -1,21 +1,30 @@
1 1
  
2 2
 
3
-
3
+import java.util.Scanner;
4 4
 public class IntegerPrinter {
5
-
5
+        Scanner scan = new Scanner(System.in);
6 6
     public String printIntegerAsBinary(int value){
7
-        return null;
7
+        //value = scan.nextInt();
8
+        
9
+        return Integer.toBinaryString(value);
8 10
     }
9 11
 
10 12
     public String printIntegerAsOctal(int value){
11
-        return null;
13
+        
14
+        
15
+        return Integer.toOctalString(value);
16
+        
17
+       
12 18
     }
13 19
 
14 20
     public String printIntegerAsHexadecimal(int value){
15
-        return null;
21
+        //value = scan.nextInt();
22
+        
23
+        return Integer.toHexString(value);
24
+        
16 25
     }
17 26
 
18 27
     public static void main(String[] args){
19
-
28
+        IntegerPrinter print = new IntegerPrinter();
20 29
     }
21 30
 }

二进制
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

+ 25
- 3
LargestInteger.java 查看文件

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

二进制
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

+ 1
- 0
LargestIntegerTest.java 查看文件

@@ -37,4 +37,5 @@ public class LargestIntegerTest {
37 37
         // :Then
38 38
         Assert.assertEquals("The Largest Number should be 600.", expected, actual);
39 39
     }
40
+    
40 41
 }

二进制
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=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

+ 13
- 5
NormalizeAngle.java 查看文件

@@ -1,17 +1,25 @@
1 1
  
2 2
 
3
-
3
+import java.util.Scanner;
4 4
 public class NormalizeAngle {
5
-
5
+    
6
+    Scanner scan = new Scanner(System.in);
7
+    
6 8
     public Integer normalizeValueUsingModulo(Integer angle){
7
-        return 0;
9
+        
10
+        
11
+        return (angle % 360);
8 12
     }
9 13
 
10 14
     public Integer normalizeValueUsingFloorMod(Integer integer){
11
-        return 0;
15
+        
16
+        
17
+        return Math.floorMod(integer,360);
18
+        
19
+        
12 20
     }
13 21
 
14 22
     public static void main(String[] args){
15
-
23
+        NormalizeAngle norm = new NormalizeAngle();
16 24
     }
17 25
 }

二进制
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\ sum(short,\ short)
5
+comment2.params=x\ y
6
+comment2.target=short\ diff(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
+comment5.params=x\ y
12
+comment5.target=short\ remainder(short,\ short)
13
+numComments=6

+ 24
- 2
ShortCalculator.java 查看文件

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

二进制
ShortCalculatorTest.class 查看文件


+ 23
- 0
ShortCalculatorTest.ctxt 查看文件

@@ -0,0 +1,23 @@
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
+comment1.text=\n\ Default\ constructor\ for\ test\ class\ ShortCalculatorTest\n
7
+comment2.params=
8
+comment2.target=void\ setUp()
9
+comment2.text=\n\ Sets\ up\ the\ test\ fixture.\n\n\ Called\ before\ every\ test\ case\ method.\n
10
+comment3.params=
11
+comment3.target=void\ tearDown()
12
+comment3.text=\n\ Tears\ down\ the\ test\ fixture.\n\n\ Called\ after\ every\ test\ case\ method.\n
13
+comment4.params=
14
+comment4.target=void\ shortSumTest()
15
+comment5.params=
16
+comment5.target=void\ shortDiffTest()
17
+comment6.params=
18
+comment6.target=void\ shortMultiplyTest()
19
+comment7.params=
20
+comment7.target=void\ shortDivideTest()
21
+comment8.params=
22
+comment8.target=void\ shortModTest()
23
+numComments=9

+ 103
- 2
ShortCalculatorTest.java 查看文件

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

+ 34
- 30
package.bluej 查看文件

@@ -1,20 +1,23 @@
1 1
 #BlueJ package file
2
-dependency1.from=LargestIntegerTest
3
-dependency1.to=LargestInteger
2
+dependency1.from=IntegerPrinterTest
3
+dependency1.to=IntegerPrinter
4 4
 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=LargestIntegerTest
9
+dependency3.to=LargestInteger
10 10
 dependency3.type=UsesDependency
11
-dependency4.from=IntegerPrinterTest
12
-dependency4.to=IntegerPrinter
11
+dependency4.from=ShortCalculatorTest
12
+dependency4.to=ShortCalculator
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=FactorialTest
15
+dependency5.to=Factorial
16
+dependency5.type=UsesDependency
17
+editor.fx.0.height=722
18
+editor.fx.0.width=800
19
+editor.fx.0.x=615
20
+editor.fx.0.y=174
18 21
 objectbench.height=101
19 22
 objectbench.width=1070
20 23
 package.divider.horizontal=0.6
@@ -25,7 +28,7 @@ package.editor.x=59
25 28
 package.editor.y=82
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
@@ -40,22 +43,22 @@ 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=560
47
+target1.y=70
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=110
54
+target10.y=470
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=330
61
+target2.y=180
59 62
 target3.height=50
60 63
 target3.name=IntegerPrinter
61 64
 target3.showInterface=false
@@ -63,45 +66,46 @@ target3.type=ClassTarget
63 66
 target3.width=110
64 67
 target3.x=10
65 68
 target3.y=130
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=210
76
+target4.y=90
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
82
+target5.x=500
79 83
 target5.y=190
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=670
90
+target6.y=220
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=240
97
+target7.y=60
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=290
104
+target8.y=340
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=660
111
+target9.y=120