jpsp91 6 år sedan
förälder
incheckning
b3e93259d8
17 ändrade filer med 101 tillägg och 74 borttagningar
  1. Binär
      Factorial.class
  2. 17
    3
      Factorial.java
  3. Binär
      FactorialTest.class
  4. 0
    2
      FactorialTest.java
  5. Binär
      LargestInteger.class
  6. 3
    3
      LargestInteger.java
  7. Binär
      NormalizeAngle.class
  8. 6
    2
      NormalizeAngle.java
  9. Binär
      ShortCalculator.class
  10. 11
    1
      ShortCalculator.ctxt
  11. 45
    1
      ShortCalculator.java
  12. Binär
      ShortCalculatorTest.class
  13. 3
    9
      ShortCalculatorTest.ctxt
  14. 16
    26
      ShortCalculatorTest.java
  15. Binär
      Test.class
  16. 0
    5
      Test.ctxt
  17. 0
    22
      Test.java

Binär
Factorial.class Visa fil


+ 17
- 3
Factorial.java Visa fil

@@ -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är
FactorialTest.class Visa fil


+ 0
- 2
FactorialTest.java Visa fil

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

Binär
LargestInteger.class Visa fil


+ 3
- 3
LargestInteger.java Visa fil

@@ -8,9 +8,9 @@ public class LargestInteger {
8 8
 
9 9
         int maxValue = 0;
10 10
 
11
-        int count = 0;
11
+        //int count = 0;
12 12
 
13
-        for (count = 0; count < integers.length; count++){
13
+        for (int count = 0; count < integers.length; count++){
14 14
 
15 15
             if(integers[count]>maxValue){
16 16
                 maxValue = integers[count];
@@ -21,7 +21,7 @@ public class LargestInteger {
21 21
         
22 22
         return maxValue;
23 23
     }
24
-
24
+    
25 25
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
26 26
         return Math.max(integers[0],(Math.max(integers[1], integers[2])));
27 27
     }

Binär
NormalizeAngle.class Visa fil


+ 6
- 2
NormalizeAngle.java Visa fil

@@ -4,11 +4,15 @@
4 4
 public class NormalizeAngle {
5 5
 
6 6
     public Integer normalizeValueUsingModulo(Integer angle){
7
-        return ((0 + 359) % angle + angle) % angle;
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 Math.floorMod(0 + 359, integer);
15
+        return Math.floorMod(integer, 360);
12 16
     }
13 17
     
14 18
     public static void main(String[] args){

Binär
ShortCalculator.class Visa fil


+ 11
- 1
ShortCalculator.ctxt Visa fil

@@ -1,3 +1,13 @@
1 1
 #BlueJ class context
2 2
 comment0.target=ShortCalculator
3
-numComments=1
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 Visa fil

@@ -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är
ShortCalculatorTest.class Visa fil


+ 3
- 9
ShortCalculatorTest.ctxt Visa fil

@@ -1,13 +1,7 @@
1 1
 #BlueJ class context
2 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 3
 comment1.params=
5
-comment1.target=ShortCalculatorTest()
6
-comment1.text=\n\ Default\ constructor\ for\ test\ class\ ShortCalculatorTest\n
4
+comment1.target=void\ setUp()
7 5
 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
-numComments=4
6
+comment2.target=void\ shortCalculatorTest()
7
+numComments=3

+ 16
- 26
ShortCalculatorTest.java Visa fil

@@ -1,35 +1,25 @@
1
-import static org.junit.Assert.*;
1
+
2 2
 import org.junit.After;
3
+import org.junit.Assert;
3 4
 import org.junit.Before;
4 5
 import org.junit.Test;
5 6
 
7
+public class ShortCalculatorTest{
8
+    private ShortCalculator shortCalculator;
6 9
 
7
-public class ShortCalculatorTest
8
-{
9
-    /**
10
-     * Default constructor for test class ShortCalculatorTest
11
-     */
12
-    public ShortCalculatorTest()
13
-    {
14
-    }
15
-
16
-    /**
17
-     * Sets up the test fixture.
18
-     *
19
-     * Called before every test case method.
20
-     */
21 10
     @Before
22
-    public void setUp()
23
-    {
11
+    public void setUp(){
12
+        shortCalculator = new ShortCalculator();
24 13
     }
25
-
26
-    /**
27
-     * Tears down the test fixture.
28
-     *
29
-     * Called after every test case method.
30
-     */
31
-    @After
32
-    public void tearDown()
33
-    {
14
+    
15
+    @Test
16
+    public void shortCalculatorTest(){
17
+        {
18
+            Short expected = 0;
19
+            
20
+            Short actual = 0;
21
+            
22
+            Assert.assertEquals(expected, actual);
23
+        }
34 24
     }
35 25
 }

Binär
Test.class Visa fil


+ 0
- 5
Test.ctxt Visa fil

@@ -1,5 +0,0 @@
1
-#BlueJ class context
2
-comment0.target=Test
3
-comment1.params=args
4
-comment1.target=void\ main(java.lang.String[])
5
-numComments=2

+ 0
- 22
Test.java Visa fil

@@ -1,22 +0,0 @@
1
-import java.util.Arrays;
2
-public class Test
3
-{
4
-
5
-    public static void main(String[] args) {
6
-        
7
-        int[] numbers = {0, 3, 2, 1, 5, 4};
8
-        
9
-        Arrays.sort(numbers);
10
-        
11
-        System.out.println(Arrays.toString(numbers));
12
-        
13
-        int x = numbers.length;
14
-        
15
-        System.out.println(x);
16
-        
17
-        System.out.println(numbers[x]);
18
-        
19
-        
20
-    }
21
-
22
-}