alizalang 6 lat temu
rodzic
commit
aa6828a934

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

+ 6
- 6
Factorial.java Wyświetl plik

@@ -1,12 +1,12 @@
1
- 
2
-
3
-
4 1
 import java.math.BigInteger;
5 2
 
6 3
 public class Factorial {
7 4
 
8 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
+}

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

BIN
IntegerPrinter.class Wyświetl plik


+ 11
- 0
IntegerPrinter.ctxt Wyświetl plik

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

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

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

+ 11
- 5
LargestInteger.java Wyświetl plik

@@ -1,13 +1,19 @@
1
- 
2
-
3 1
 
4 2
 public class LargestInteger {
5 3
 
6 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 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
+}

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

@@ -1,17 +1,16 @@
1
- 
2
-
3
-
4 1
 public class NormalizeAngle {
5 2
 
6 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 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 13
     public static void main(String[] args){
15 14
 
16 15
     }
17
-}
16
+}

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


+ 5
- 0
RunCalculator.ctxt Wyświetl plik

@@ -0,0 +1,5 @@
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 Wyświetl plik

@@ -0,0 +1,28 @@
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
+}

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

@@ -1,5 +1,22 @@
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
+}

BIN
ShortCalculatorTest.class Wyświetl plik


+ 15
- 0
ShortCalculatorTest.ctxt Wyświetl plik

@@ -0,0 +1,15 @@
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 Wyświetl plik

@@ -1,5 +1,65 @@
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 Wyświetl plik

@@ -16,8 +16,8 @@ editor.fx.0.width=0
16 16
 editor.fx.0.x=0
17 17
 editor.fx.0.y=0
18 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 21
 package.divider.vertical=0.837593984962406
22 22
 package.editor.height=550
23 23
 package.editor.width=968
@@ -26,7 +26,7 @@ package.editor.y=82
26 26
 package.frame.height=723
27 27
 package.frame.width=1094
28 28
 package.numDependencies=4
29
-package.numTargets=10
29
+package.numTargets=11
30 30
 package.showExtends=true
31 31
 package.showUses=true
32 32
 project.charset=UTF-8
@@ -49,6 +49,13 @@ target10.type=UnitTestTargetJunit4
49 49
 target10.width=140
50 50
 target10.x=10
51 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 59
 target2.height=50
53 60
 target2.name=NormalizeAngle
54 61
 target2.showInterface=false
@@ -87,7 +94,7 @@ target6.y=190
87 94
 target7.height=50
88 95
 target7.name=ShortCalculatorTest
89 96
 target7.showInterface=false
90
-target7.type=ClassTarget
97
+target7.type=UnitTestTargetJunit4
91 98
 target7.width=150
92 99
 target7.x=10
93 100
 target7.y=250