#25 Baisc Computation

Open
jpsp91 wants to merge 2 commits from jpsp91/ZCW-BasicComputations-BlueJ:master into master

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

+ 17
- 3
Factorial.java View File

@@ -1,12 +1,26 @@
1
- 
2
-
3 1
 
4 2
 import java.math.BigInteger;
5 3
 
4
+//Write a program that computes the factorial n! = 1 x 2 x ... x n, 
5
+//using BigInteger. Compute the factorial of 1000.
6
+
6 7
 public class Factorial {
7 8
 
8 9
     public BigInteger factorialOf(Integer value){
9
-        return null;
10
+        int i = 1;
11
+        int j = 1;
12
+        
13
+        
14
+        
15
+        for(i = 1; i <= value; i++){
16
+            j=j*i;
17
+        }
18
+        
19
+        //j is the factorial of value
20
+        
21
+        BigInteger x = BigInteger.valueOf(j);
22
+        
23
+        return x;
10 24
     }
11 25
 
12 26
 }

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

+ 0
- 2
FactorialTest.java View File

@@ -1,5 +1,3 @@
1
- 
2
-
3 1
 
4 2
 import org.junit.Assert;
5 3
 import org.junit.Before;

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

+ 6
- 4
IntegerPrinter.java View File

@@ -1,18 +1,20 @@
1
- 
2 1
 
3 2
 
4 3
 public class IntegerPrinter {
5 4
 
6 5
     public String printIntegerAsBinary(int value){
7
-        return null;
6
+        
7
+        return Integer.toBinaryString(value);
8 8
     }
9 9
 
10 10
     public String printIntegerAsOctal(int value){
11
-        return null;
11
+        
12
+        return Integer.toOctalString(value);
12 13
     }
13 14
 
14 15
     public String printIntegerAsHexadecimal(int value){
15
-        return null;
16
+        
17
+        return Integer.toHexString(value);
16 18
     }
17 19
 
18 20
     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

+ 0
- 3
IntegerPrinterTest.java View File

@@ -1,6 +1,3 @@
1
- 
2
-
3
-
4 1
 import org.junit.Assert;
5 2
 import org.junit.Before;
6 3
 import org.junit.Test;

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

+ 21
- 5
LargestInteger.java View File

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

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

+ 7
- 3
NormalizeAngle.java View File

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

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=firstValue\ SecondValue
4
+comment1.target=java.lang.Short\ shortCalculatorSum(java.lang.Integer,\ java.lang.Integer)
5
+comment2.params=firstValue\ SecondValue
6
+comment2.target=java.lang.Short\ shortCalculatorDifference(java.lang.Integer,\ java.lang.Integer)
7
+comment3.params=firstValue\ SecondValue
8
+comment3.target=java.lang.Short\ shortCalculatorProduct(java.lang.Integer,\ java.lang.Integer)
9
+comment4.params=firstValue\ SecondValue
10
+comment4.target=java.lang.Short\ shortCalculatorQuotient(java.lang.Integer,\ java.lang.Integer)
11
+comment5.params=firstValue\ SecondValue
12
+comment5.target=java.lang.Short\ shortCalculatorRemainder(java.lang.Integer,\ java.lang.Integer)
13
+numComments=6

+ 45
- 1
ShortCalculator.java View File

@@ -1,5 +1,49 @@
1
- 
2 1
 
3 2
 
4 3
 public class ShortCalculator {
4
+    
5
+    public Short shortCalculatorSum (Integer firstValue, Integer SecondValue){
6
+        
7
+        int x = firstValue + SecondValue;
8
+        
9
+        short xShort = (short)x;
10
+        
11
+        return xShort;
12
+    }
13
+
14
+    public Short shortCalculatorDifference (Integer firstValue, Integer SecondValue){
15
+        
16
+        int x = firstValue - SecondValue;
17
+        
18
+        short xShort = (short)x;
19
+        
20
+        return xShort;
21
+    }
22
+    
23
+    public Short shortCalculatorProduct (Integer firstValue, Integer SecondValue){
24
+        
25
+        int x = firstValue * SecondValue;
26
+        
27
+        short xShort = (short)x;
28
+        
29
+        return xShort;
30
+    }
31
+    
32
+    public Short shortCalculatorQuotient (Integer firstValue, Integer SecondValue){
33
+        
34
+        int x = firstValue / SecondValue;
35
+        
36
+        short xShort = (short)x;
37
+        
38
+        return xShort;
39
+    }
40
+    
41
+    public Short shortCalculatorRemainder (Integer firstValue, Integer SecondValue){
42
+        
43
+        int x = firstValue % SecondValue;
44
+        
45
+        short xShort = (short)x;
46
+        
47
+        return xShort;
48
+    }
5 49
 }

BIN
ShortCalculatorTest.class View File


+ 7
- 0
ShortCalculatorTest.ctxt View File

@@ -0,0 +1,7 @@
1
+#BlueJ class context
2
+comment0.target=ShortCalculatorTest
3
+comment1.params=
4
+comment1.target=void\ setUp()
5
+comment2.params=
6
+comment2.target=void\ shortCalculatorTest()
7
+numComments=3

+ 22
- 2
ShortCalculatorTest.java View File

@@ -1,5 +1,25 @@
1
- 
2 1
 
2
+import org.junit.After;
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
3 6
 
4
-public class ShortCalculatorTest {
7
+public class ShortCalculatorTest{
8
+    private ShortCalculator shortCalculator;
9
+
10
+    @Before
11
+    public void setUp(){
12
+        shortCalculator = new ShortCalculator();
13
+    }
14
+    
15
+    @Test
16
+    public void shortCalculatorTest(){
17
+        {
18
+            Short expected = 0;
19
+            
20
+            Short actual = 0;
21
+            
22
+            Assert.assertEquals(expected, actual);
23
+        }
24
+    }
5 25
 }

+ 1
- 1
package.bluej View File

@@ -22,7 +22,7 @@ package.divider.vertical=0.837593984962406
22 22
 package.editor.height=550
23 23
 package.editor.width=968
24 24
 package.editor.x=59
25
-package.editor.y=82
25
+package.editor.y=24
26 26
 package.frame.height=723
27 27
 package.frame.width=1094
28 28
 package.numDependencies=4