nafis nibir 6 vuotta sitten
vanhempi
commit
9a845ccecb

BIN
Factorial.class Näytä tiedosto


+ 8
- 6
Factorial.java Näytä tiedosto

@@ -1,12 +1,14 @@
1
- 
2
-
3 1
 
4 2
 import java.math.BigInteger;
5
-
6 3
 public class Factorial {
7
-
8 4
     public BigInteger factorialOf(Integer value){
9
-        return null;
5
+        int x = 1;
6
+        for (int i = 1; i<=value; i++){
7
+            x = x * i;
8
+        }
9
+        BigInteger ans = BigInteger.valueOf(x);
10
+        return ans;
10 11
     }
11
-
12 12
 }
13
+
14
+

BIN
FactorialTest.class Näytä tiedosto


+ 0
- 1
FactorialTest.java Näytä tiedosto

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

BIN
IntegerPrinter.class Näytä tiedosto


+ 6
- 6
IntegerPrinter.java Näytä tiedosto

@@ -3,18 +3,18 @@
3 3
 public class IntegerPrinter {
4 4
 
5 5
     public String printIntegerAsBinary(int value){
6
-        String x = Integer.toBinaryString(value);
7
-        return x;
6
+        //String x = Integer.toBinaryString(value);
7
+        return Integer.toBinaryString(value);
8 8
     }
9 9
 
10 10
     public String printIntegerAsOctal(int value){
11
-        String x = Integer.toOctalString(value);
12
-        return x;
11
+        //String x = Integer.toOctalString(value);
12
+        return Integer.toOctalString(value);
13 13
     }
14 14
 
15 15
     public String printIntegerAsHexadecimal(int value){
16
-        String x = Integer.toHexString(value);
17
-        return x;
16
+        //String x = Integer.toHexString(value);
17
+        return Integer.toHexString(value);
18 18
     }
19 19
 
20 20
     public static void main(String[] args){

BIN
ShortCalculator.class Näytä tiedosto


+ 13
- 1
ShortCalculator.ctxt Näytä tiedosto

@@ -1,3 +1,15 @@
1 1
 #BlueJ class context
2 2
 comment0.target=ShortCalculator
3
-numComments=1
3
+comment1.params=x\ y
4
+comment1.target=void\ calculator(short,\ short)
5
+comment2.params=a\ b
6
+comment2.target=short\ add(short,\ short)
7
+comment3.params=a\ b
8
+comment3.target=short\ subtract(short,\ short)
9
+comment4.params=a\ b
10
+comment4.target=short\ multiply(short,\ short)
11
+comment5.params=a\ b
12
+comment5.target=short\ divide(short,\ short)
13
+comment6.params=a\ b
14
+comment6.target=short\ remainder(short,\ short)
15
+numComments=7

+ 41
- 1
ShortCalculator.java Näytä tiedosto

@@ -1,5 +1,45 @@
1
- 
2 1
 
3 2
 
4 3
 public class ShortCalculator {
4
+    
5
+    public void calculator(short x, short y){
6
+        
7
+        
8
+        add(x,y);
9
+        subtract(x,y);
10
+        multiply(x,y);
11
+        divide(x,y);
12
+        remainder(x,y);
13
+        
14
+    }
15
+    
16
+    public short add(short a, short b){
17
+        return (short)(a+b);
18
+    }
19
+    
20
+    public short subtract(short a, short b){
21
+        return (short)(a-b);
22
+    }
23
+    
24
+    public short multiply(short a, short b){
25
+        return (short)(a*b);
26
+    }
27
+    
28
+    public short divide(short a, short b){
29
+        return (short)(a/b);
30
+    }
31
+    
32
+    public short remainder(short a, short b){
33
+        return (short)(a%b);
34
+    }
35
+    /*
36
+     * Write a program that reads in two numbers between 0 and 65535, 
37
+     * stores them in short variables, and computes their unsigned sum,
38
+     * difference, product, quotient, and remainder , 
39
+     * without converting them to int.
40
+     */
41
+    
42
+    
43
+   
5 44
 }
45
+

BIN
ShortCalculatorTest.class Näytä tiedosto


+ 13
- 1
ShortCalculatorTest.ctxt Näytä tiedosto

@@ -1,3 +1,15 @@
1 1
 #BlueJ class context
2 2
 comment0.target=ShortCalculatorTest
3
-numComments=1
3
+comment1.params=
4
+comment1.target=ShortCalculatorTest()
5
+comment2.params=
6
+comment2.target=void\ testAdd()
7
+comment3.params=
8
+comment3.target=void\ testSubtract()
9
+comment4.params=
10
+comment4.target=void\ testMultiply()
11
+comment5.params=
12
+comment5.target=void\ testDivide()
13
+comment6.params=
14
+comment6.target=void\ testRemainder()
15
+numComments=7

+ 71
- 1
ShortCalculatorTest.java Näytä tiedosto

@@ -1,5 +1,75 @@
1
- 
1
+import static org.junit.Assert.*;
2
+import org.junit.After;
3
+import org.junit.Before;
4
+import org.junit.Test;
2 5
 
3 6
 
4 7
 public class ShortCalculatorTest {
8
+    ShortCalculator test;
9
+    
10
+    public ShortCalculatorTest() {
11
+        test = new ShortCalculator(); 
12
+    }
13
+    
14
+    @Test
15
+    public void testAdd(){
16
+        //expected
17
+        short expected = 10;
18
+        //actual
19
+        short actual =test.add((short)5,(short)5);
20
+        //then
21
+        assertEquals(expected, actual);
22
+        
23
+        
24
+    }
25
+    
26
+    @Test
27
+    public void testSubtract(){
28
+        //expected
29
+        short expected = 5;
30
+        //actual
31
+        short actual =test.subtract((short)10,(short)5);
32
+        //then
33
+        assertEquals(expected, actual);
34
+        
35
+        
36
+    }
37
+    
38
+    @Test
39
+    public void testMultiply(){
40
+        //expected
41
+        short expected = 25;
42
+        //actual
43
+        short actual =test.multiply((short)5,(short)5);
44
+        //then
45
+        assertEquals(expected, actual);
46
+        
47
+        
48
+    }
49
+    
50
+    @Test
51
+    public void testDivide(){
52
+        //expected
53
+        short expected = 5;
54
+        //actual
55
+        short actual =test.divide((short)10,(short)2);
56
+        //then
57
+        assertEquals(expected, actual);
58
+        
59
+        
60
+    }
61
+    
62
+    @Test
63
+    public void testRemainder(){
64
+        //expected
65
+        short expected = 1;
66
+        //actual
67
+        short actual =test.remainder((short)10,(short)3);
68
+        //then
69
+        assertEquals(expected, actual);
70
+        
71
+        
72
+    }
73
+ 
74
+    
5 75
 }