Bläddra i källkod

completed IntegerPrinter and Factorial

Rachelle 6 år sedan
förälder
incheckning
15ff259038
11 ändrade filer med 81 tillägg och 42 borttagningar
  1. Binär
      Factorial.class
  2. 5
    0
      Factorial.ctxt
  3. 8
    3
      Factorial.java
  4. Binär
      FactorialTest.class
  5. 7
    0
      FactorialTest.ctxt
  6. Binär
      IntegerPrinter.class
  7. 11
    0
      IntegerPrinter.ctxt
  8. 3
    3
      IntegerPrinter.java
  9. Binär
      IntegerPrinterTest.class
  10. 11
    0
      IntegerPrinterTest.ctxt
  11. 36
    36
      package.bluej

Binär
Factorial.class Visa fil


+ 5
- 0
Factorial.ctxt Visa fil

@@ -0,0 +1,5 @@
1
+#BlueJ class context
2
+comment0.target=Factorial
3
+comment1.params=value
4
+comment1.target=java.math.BigInteger\ factorialOf(int)
5
+numComments=2

+ 8
- 3
Factorial.java Visa fil

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

Binär
FactorialTest.class Visa fil


+ 7
- 0
FactorialTest.ctxt Visa fil

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


+ 11
- 0
IntegerPrinter.ctxt Visa fil

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

@@ -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 String.format("%o",value);
12 12
     }
13 13
 
14 14
     public String printIntegerAsHexadecimal(int value){
15
-        return null;
15
+        return String.format("%x",value);
16 16
     }
17 17
 
18 18
     public static void main(String[] args){

Binär
IntegerPrinterTest.class Visa fil


+ 11
- 0
IntegerPrinterTest.ctxt Visa fil

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

+ 36
- 36
package.bluej Visa fil

@@ -1,29 +1,29 @@
1 1
 #BlueJ package file
2
-dependency1.from=LargestIntegerTest
3
-dependency1.to=LargestInteger
2
+dependency1.from=IntegerPrinterTest
3
+dependency1.to=IntegerPrinter
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=NormalizeAngleTest
6
-dependency2.to=NormalizeAngle
5
+dependency2.from=LargestIntegerTest
6
+dependency2.to=LargestInteger
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=FactorialTest
9
-dependency3.to=Factorial
8
+dependency3.from=NormalizeAngleTest
9
+dependency3.to=NormalizeAngle
10 10
 dependency3.type=UsesDependency
11
-dependency4.from=IntegerPrinterTest
12
-dependency4.to=IntegerPrinter
11
+dependency4.from=FactorialTest
12
+dependency4.to=Factorial
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
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
14
+editor.fx.0.height=709
15
+editor.fx.0.width=800
16
+editor.fx.0.x=240
17
+editor.fx.0.y=23
18
+objectbench.height=98
19
+objectbench.width=637
20
+package.divider.horizontal=0.5996275605214153
21
+package.divider.vertical=0.8387096774193549
22
+package.editor.height=539
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=99
25
+package.editor.y=23
26
+package.frame.height=709
27 27
 package.frame.width=1094
28 28
 package.numDependencies=4
29 29
 package.numTargets=10
@@ -40,8 +40,8 @@ target1.name=Factorial
40 40
 target1.showInterface=false
41 41
 target1.type=ClassTarget
42 42
 target1.width=80
43
-target1.x=160
44
-target1.y=10
43
+target1.x=540
44
+target1.y=40
45 45
 target10.height=50
46 46
 target10.name=IntegerPrinterTest
47 47
 target10.showInterface=false
@@ -54,29 +54,29 @@ target2.name=NormalizeAngle
54 54
 target2.showInterface=false
55 55
 target2.type=ClassTarget
56 56
 target2.width=120
57
-target2.x=70
58
-target2.y=70
57
+target2.x=520
58
+target2.y=150
59 59
 target3.height=50
60 60
 target3.name=IntegerPrinter
61 61
 target3.showInterface=false
62 62
 target3.type=ClassTarget
63 63
 target3.width=110
64
-target3.x=10
65
-target3.y=130
64
+target3.x=20
65
+target3.y=390
66 66
 target4.height=50
67 67
 target4.name=ShortCalculator
68 68
 target4.showInterface=false
69 69
 target4.type=ClassTarget
70 70
 target4.width=120
71
-target4.x=130
72
-target4.y=130
71
+target4.x=90
72
+target4.y=50
73 73
 target5.height=50
74 74
 target5.name=LargestInteger
75 75
 target5.showInterface=false
76 76
 target5.type=ClassTarget
77 77
 target5.width=120
78
-target5.x=10
79
-target5.y=190
78
+target5.x=260
79
+target5.y=210
80 80
 target6.height=50
81 81
 target6.name=LargestIntegerTest
82 82
 target6.showInterface=false
@@ -89,19 +89,19 @@ target7.name=ShortCalculatorTest
89 89
 target7.showInterface=false
90 90
 target7.type=ClassTarget
91 91
 target7.width=150
92
-target7.x=10
93
-target7.y=250
92
+target7.x=240
93
+target7.y=50
94 94
 target8.height=50
95 95
 target8.name=NormalizeAngleTest
96 96
 target8.showInterface=false
97 97
 target8.type=UnitTestTargetJunit4
98 98
 target8.width=150
99
-target8.x=10
100
-target8.y=310
99
+target8.x=500
100
+target8.y=140
101 101
 target9.height=50
102 102
 target9.name=FactorialTest
103 103
 target9.showInterface=false
104 104
 target9.type=UnitTestTargetJunit4
105 105
 target9.width=110
106
-target9.x=410
107
-target9.y=260
106
+target9.x=530
107
+target9.y=20