Browse Source

finished the lab

Roy 6 years ago
parent
commit
586614bf9e

BIN
Factorial.class View File


+ 5
- 0
Factorial.ctxt View File

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

@@ -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 num = new BigInteger("1");
10
+        for (int i =2; i<=value; i++){
11
+            num = num.multiply(BigInteger.valueOf(i));
12
+        }
13
+        return num;
10 14
     }
11 15
 
12 16
 }

BIN
FactorialTest.class View File


+ 7
- 0
FactorialTest.ctxt View File

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


+ 11
- 0
IntegerPrinter.ctxt View File

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

+ 28
- 6
IntegerPrinter.java View File

@@ -1,18 +1,40 @@
1
- 
2
-
3 1
 
4 2
 public class IntegerPrinter {
5
-
6 3
     public String printIntegerAsBinary(int value){
7
-        return null;
4
+        StringBuilder binary = new StringBuilder();
5
+
6
+        while(value >= 1) {
7
+            if (value / 2 >= 1) binary.append(value % 2);
8
+            value /= 2;
9
+        }
10
+
11
+        return binary.append("1").reverse().toString();
8 12
     }
9 13
 
10 14
     public String printIntegerAsOctal(int value){
11
-        return null;
15
+        StringBuilder baseEight = new StringBuilder();
16
+        while((value/8) >= 1){//
17
+            baseEight.append(value % 8);
18
+            value /= 8;
19
+        }
20
+        return baseEight.append(value).reverse().toString();
12 21
     }
13 22
 
14 23
     public String printIntegerAsHexadecimal(int value){
15
-        return null;
24
+        StringBuilder baseSixteen = new StringBuilder();
25
+        while((value/16) != 0){
26
+            if ((value / 16) >= 1) {
27
+                if((value%16) >= 10){
28
+                    baseSixteen.append((char) (87+(value%16)));
29
+                }
30
+                else{
31
+                    baseSixteen.append(value % 16);
32
+                }
33
+                value /= 16;
34
+            }
35
+        }
36
+        value = value >= 10 ? (char) 87+(value%16) : value;
37
+        return baseSixteen.append(value).reverse().toString();
16 38
     }
17 39
 
18 40
     public static void main(String[] args){

BIN
IntegerPrinterTest.class View File


+ 11
- 0
IntegerPrinterTest.ctxt View File

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


+ 7
- 0
LargestInteger.ctxt View File

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

+ 14
- 3
LargestInteger.java View File

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

BIN
LargestIntegerTest.class View File


+ 9
- 0
LargestIntegerTest.ctxt View File

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


+ 9
- 0
NormalizeAngle.ctxt View File

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

+ 10
- 3
NormalizeAngle.java View File

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

BIN
NormalizeAngleTest.class View File


+ 9
- 0
NormalizeAngleTest.ctxt View File

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


+ 13
- 0
ShortCalculator.ctxt View File

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

+ 17
- 0
ShortCalculator.java View File

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

+ 0
- 5
ShortCalculatorTest.java View File

@@ -1,5 +0,0 @@
1
- 
2
-
3
-
4
-public class ShortCalculatorTest {
5
-}

+ 11
- 11
package.bluej View File

@@ -11,19 +11,19 @@ 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
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 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
19
+objectbench.width=637
20
+package.divider.horizontal=0.5996275605214153
21
+package.divider.vertical=0.8353658536585366
22
+package.editor.height=541
23 23
 package.editor.width=968
24
-package.editor.x=59
25
-package.editor.y=82
26
-package.frame.height=723
24
+package.editor.x=68
25
+package.editor.y=23
26
+package.frame.height=714
27 27
 package.frame.width=1094
28 28
 package.numDependencies=4
29 29
 package.numTargets=10