Eric Foster 6 lat temu
rodzic
commit
c0077ac15f

BIN
Factorial.class Wyświetl plik


+ 5
- 0
Factorial.ctxt Wyświetl plik

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

+ 5
- 1
Factorial.java Wyświetl plik

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

BIN
FactorialTest.class Wyświetl plik


+ 7
- 0
FactorialTest.ctxt Wyświetl plik

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

+ 1
- 1
FactorialTest.java Wyświetl plik

@@ -20,7 +20,7 @@ public class FactorialTest {
20 20
     public void factorialOfTest(){
21 21
         //:Given
22 22
         BigInteger expected = new BigInteger("24");
23
-
23
+        
24 24
         //:When
25 25
         BigInteger actual = factorial.factorialOf(4);
26 26
 

BIN
IntegerPrinter.class Wyświetl plik


+ 12
- 0
IntegerPrinter.ctxt Wyświetl plik

@@ -0,0 +1,12 @@
1
+#BlueJ class context
2
+comment0.target=IntegerPrinter
3
+comment0.text=\n\ Write\ a\ program\ that\ reads\ an\ integer\ and\ prints\ it\ in\n\ binary,\ octal,\ hexadecimal\n
4
+comment1.params=value
5
+comment1.target=java.lang.String\ printIntegerAsBinary(int)
6
+comment2.params=value
7
+comment2.target=java.lang.String\ printIntegerAsOctal(int)
8
+comment3.params=value
9
+comment3.target=java.lang.String\ printIntegerAsHexadecimal(int)
10
+comment4.params=args
11
+comment4.target=void\ main(java.lang.String[])
12
+numComments=5

+ 11
- 7
IntegerPrinter.java Wyświetl plik

@@ -1,21 +1,25 @@
1
- 
2
-
1
+/**
2
+ * Write a program that reads an integer and prints it in
3
+ * binary, octal, hexadecimal
4
+ */ 
3 5
 
4 6
 public class IntegerPrinter {
5
-
6 7
     public String printIntegerAsBinary(int value){
7
-        return null;
8
+        String binary = Integer.toBinaryString(value);
9
+        return binary;
8 10
     }
9 11
 
10 12
     public String printIntegerAsOctal(int value){
11
-        return null;
13
+        String octal = Integer.toOctalString(value);
14
+        return octal;
12 15
     }
13 16
 
14 17
     public String printIntegerAsHexadecimal(int value){
15
-        return null;
18
+        String hex = Integer.toHexString(value);
19
+        return hex;
16 20
     }
17 21
 
18 22
     public static void main(String[] args){
19
-
23
+        
20 24
     }
21 25
 }

BIN
IntegerPrinterTest.class Wyświetl plik


+ 11
- 0
IntegerPrinterTest.ctxt Wyświetl plik

@@ -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
LargestInteger.class Wyświetl plik


+ 7
- 0
LargestInteger.ctxt Wyświetl plik

@@ -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 Wyświetl plik

@@ -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 maxNum = integers[0];
7
+        for(int i=1; i<integers.length;i++){
8
+            int newMax = integers[i] >= integers[i-1] ? integers[i] : maxNum;
9
+            maxNum=newMax;
10
+        }
11
+        return maxNum;
8 12
     }
9 13
 
10 14
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
11
-        return null;
15
+        int maxNum = integers[0];
16
+        for(int i=1; i<integers.length;i++){
17
+            int newMax = Math.max(integers[i],maxNum);
18
+            maxNum=newMax;
19
+        }
20
+        return maxNum;
12 21
     }
13 22
 }

BIN
LargestIntegerTest.class Wyświetl plik


+ 9
- 0
LargestIntegerTest.ctxt Wyświetl plik

@@ -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
NormalizeAngle.class Wyświetl plik


+ 9
- 0
NormalizeAngle.ctxt Wyświetl plik

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

+ 7
- 6
NormalizeAngle.java Wyświetl plik

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

BIN
NormalizeAngleTest.class Wyświetl plik


+ 9
- 0
NormalizeAngleTest.ctxt Wyświetl plik

@@ -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
ShortCalculator.class Wyświetl plik


+ 13
- 0
ShortCalculator.ctxt Wyświetl plik

@@ -0,0 +1,13 @@
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
+comment5.params=x\ y
12
+comment5.target=short\ remainder(short,\ short)
13
+numComments=6

+ 19
- 1
ShortCalculator.java Wyświetl plik

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

BIN
ShortCalculatorTest.class Wyświetl plik


+ 17
- 0
ShortCalculatorTest.ctxt Wyświetl plik

@@ -0,0 +1,17 @@
1
+#BlueJ class context
2
+comment0.target=ShortCalculatorTest
3
+comment1.params=
4
+comment1.target=void\ setUp()
5
+comment2.params=
6
+comment2.target=void\ addTest()
7
+comment3.params=
8
+comment3.target=void\ addBigNumberTest()
9
+comment4.params=
10
+comment4.target=void\ subtractTest()
11
+comment5.params=
12
+comment5.target=void\ multiplyTest()
13
+comment6.params=
14
+comment6.target=void\ divideTest()
15
+comment7.params=
16
+comment7.target=void\ remainderTest()
17
+numComments=8

+ 82
- 2
ShortCalculatorTest.java Wyświetl plik

@@ -1,5 +1,85 @@
1
- 
2
-
1
+import org.junit.Assert;
2
+import org.junit.After;
3
+import org.junit.Before;
4
+import org.junit.Test;
3 5
 
4 6
 public class ShortCalculatorTest {
7
+    private ShortCalculator shortcalc;
8
+    
9
+    @Before
10
+    public void setUp(){
11
+        shortcalc = new ShortCalculator();
12
+    }
13
+    
14
+    @Test
15
+    public void addTest(){
16
+        //:Given
17
+        short expected = 300;
18
+        
19
+        //:When
20
+        short actual = shortcalc.add((short)100,(short)200);
21
+
22
+        //:Then
23
+        Assert.assertEquals("Values should be equal", expected, actual);
24
+    }
25
+    
26
+     @Test
27
+    public void addBigNumberTest(){
28
+        //:Given
29
+        short expected = (short)110000;
30
+        
31
+        //:When
32
+        short actual = shortcalc.add((short)50000,(short)60000);
33
+
34
+        //:Then
35
+        Assert.assertEquals("Values should be equal", expected, actual);
36
+    }
37
+    
38
+    @Test
39
+    public void subtractTest(){
40
+        //:Given
41
+        short expected = 1000;
42
+        
43
+        //:When
44
+        short actual = shortcalc.subtract((short)2000,(short)1000);
45
+
46
+        //:Then
47
+        Assert.assertEquals("Values should be equal", expected, actual);
48
+    }
49
+    
50
+    @Test
51
+    public void multiplyTest(){
52
+        //:Given
53
+        short expected = 363;
54
+        
55
+        //:When
56
+        short actual = shortcalc.multiply((short)33,(short)11);
57
+
58
+        //:Then
59
+        Assert.assertEquals("Values should be equal", expected, actual);
60
+    }
61
+    
62
+    @Test
63
+    public void divideTest(){
64
+        //:Given
65
+        short expected = 8;
66
+        
67
+        //:When
68
+        short actual = shortcalc.divide((short)88,(short)11);
69
+
70
+        //:Then
71
+        Assert.assertEquals("Values should be equal", expected, actual);
72
+    }
73
+    
74
+    @Test
75
+    public void remainderTest(){
76
+        //:Given
77
+        short expected = 5;
78
+        
79
+        //:When
80
+        short actual = shortcalc.remainder((short)105,(short)10);
81
+
82
+        //:Then
83
+        Assert.assertEquals("Values should be equal", expected, actual);
84
+    }
5 85
 }

+ 15
- 15
package.bluej Wyświetl plik

@@ -5,25 +5,25 @@ 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
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
+editor.fx.0.height=716
15
+editor.fx.0.width=800
16
+editor.fx.0.x=240
17
+editor.fx.0.y=23
18
+objectbench.height=183
19
+objectbench.width=637
20
+package.divider.horizontal=0.5996275605214153
21
+package.divider.vertical=0.7081413210445469
22
+package.editor.height=454
23 23
 package.editor.width=968
24 24
 package.editor.x=59
25
-package.editor.y=82
26
-package.frame.height=723
25
+package.editor.y=23
26
+package.frame.height=709
27 27
 package.frame.width=1094
28 28
 package.numDependencies=4
29 29
 package.numTargets=10