shakila 6 vuotta sitten
vanhempi
commit
2d7527d8d3

BIN
LargestInteger.class Näytä tiedosto


+ 11
- 4
LargestInteger.java Näytä tiedosto

@@ -1,13 +1,20 @@
1
- 
2
-
1
+import java.lang.Math; 
2
+import java.util.Arrays;
3 3
 
4 4
 public class LargestInteger {
5 5
 
6 6
     public Integer findLargestNumberUsingConditional(Integer[] integers){
7
-        return null;
7
+        int largest = 0;
8
+        for (int i = 0; i<integers.length; i++){
9
+            Arrays.sort(integers);
10
+            largest = integers[integers.length-1];
8 11
     }
12
+    return largest;
13
+}
9 14
 
10 15
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
11
-        return null;
16
+        Arrays.sort(integers);
17
+        
18
+        return Math.max(integers[1],integers[2]);
12 19
     }
13 20
 }

BIN
NormalizeAngle.class Näytä tiedosto


+ 6
- 4
NormalizeAngle.java Näytä tiedosto

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

BIN
ShortCalculator.class Näytä tiedosto


+ 8
- 2
ShortCalculator.ctxt Näytä tiedosto

@@ -1,5 +1,11 @@
1 1
 #BlueJ class context
2 2
 comment0.target=ShortCalculator
3 3
 comment1.params=number1\ number2
4
-comment1.target=void\ math(short,\ short)
5
-numComments=2
4
+comment1.target=java.lang.Short\ add(short,\ short)
5
+comment2.params=number1\ number2
6
+comment2.target=java.lang.Short\ subtract(short,\ short)
7
+comment3.params=number1\ number2
8
+comment3.target=java.lang.Short\ multiply(short,\ short)
9
+comment4.params=number1\ number2
10
+comment4.target=java.lang.Short\ divide(short,\ short)
11
+numComments=5

+ 37
- 5
ShortCalculator.java Näytä tiedosto

@@ -4,7 +4,7 @@
4 4
 
5 5
 public class ShortCalculator {
6 6
 
7
-public static void math(short number1,short number2){
7
+public static Short add(short number1,short number2){
8 8
     
9 9
     Scanner scanner = new Scanner(System.in);
10 10
     System.out.println("Enter the first number");
@@ -12,14 +12,46 @@ public static void math(short number1,short number2){
12 12
     System.out.println("Enter second number");
13 13
     number2 = scanner.nextShort();
14 14
     
15
-    System.out.println(number1 + (double)number2);
16
-    System.out.println(number1 - (double)number2);
17
-    System.out.println(number1 * (double)number2);
18
-    System.out.println(number1/(double)number2);
15
+    short add = (short)(number1 + number2);
16
+    System.out.println(add);
17
+    return add; 
18
+}
19 19
 
20
+public static Short subtract(short number1,short number2){
20 21
     
22
+    Scanner scanner = new Scanner(System.in);
23
+    System.out.println("Enter the first number");
24
+    number1 = scanner.nextShort();
25
+    System.out.println("Enter second number");
26
+    number2 = scanner.nextShort();
21 27
     
28
+    short subtract = (short)(number1 - number2);
29
+    System.out.println(subtract);
30
+    return subtract; 
31
+
22 32
 }
23 33
 
34
+public static Short multiply(short number1,short number2){
35
+   Scanner scanner = new Scanner(System.in);
36
+    System.out.println("Enter the first number");
37
+    number1 = scanner.nextShort();
38
+    System.out.println("Enter second number");
39
+    number2 = scanner.nextShort();
40
+    
41
+    short multiply = (short)(number1 * number2);
42
+    System.out.println(multiply);
43
+    return multiply;
44
+}
24 45
 
46
+public static Short divide(short number1,short number2){
47
+ Scanner scanner = new Scanner(System.in);
48
+    System.out.println("Enter the first number");
49
+    number1 = scanner.nextShort();
50
+    System.out.println("Enter second number");
51
+    number2 = scanner.nextShort();   
52
+    
53
+    short divide = (short)(number1/number2);
54
+    System.out.println(divide);
55
+    return divide;
56
+}
25 57
 }

BIN
ShortCalculatorTest.class Näytä tiedosto


+ 2
- 9
ShortCalculatorTest.ctxt Näytä tiedosto

@@ -2,12 +2,5 @@
2 2
 comment0.target=ShortCalculatorTest
3 3
 comment0.text=\n\ The\ test\ class\ ShortCalculatorTest.\n\n\ @author\ \ (your\ name)\n\ @version\ (a\ version\ number\ or\ a\ date)\n
4 4
 comment1.params=
5
-comment1.target=ShortCalculatorTest()
6
-comment1.text=\n\ Default\ constructor\ for\ test\ class\ ShortCalculatorTest\n
7
-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
5
+comment1.target=void\ addTest()
6
+numComments=2

+ 4
- 4
ShortCalculatorTest.java Näytä tiedosto

@@ -16,9 +16,9 @@ public class ShortCalculatorTest
16 16
 {
17 17
     @Test
18 18
     public void addTest(){
19
-    //ShortCalculator shortCalculator = new ShortCalculator();
20
-    //double expected = 388;
21
-    //double actual = ShortCalculator.math(255,133);
22
-    Assert.assertEquals(388,ShortCalculator.math(255,133),0.01);
19
+    ShortCalculator shortCalculator = new ShortCalculator();
20
+    short expected = 388;
21
+    short actual = ShortCalculator.add((short)255,(short)133);
22
+    Assert.assertEquals(expected, actual,0.01);
23 23
 }
24 24
 }

+ 33
- 29
package.bluej Näytä tiedosto

@@ -11,21 +11,24 @@ dependency3.type=UsesDependency
11 11
 dependency4.from=IntegerPrinterTest
12 12
 dependency4.to=IntegerPrinter
13 13
 dependency4.type=UsesDependency
14
+dependency5.from=ShortCalculatorTest
15
+dependency5.to=ShortCalculator
16
+dependency5.type=UsesDependency
14 17
 editor.fx.0.height=709
15 18
 editor.fx.0.width=800
16
-editor.fx.0.x=106
19
+editor.fx.0.x=162
17 20
 editor.fx.0.y=23
18 21
 objectbench.height=99
19
-objectbench.width=637
20
-package.divider.horizontal=0.5996275605214153
22
+objectbench.width=503
23
+package.divider.horizontal=0.6335403726708074
21 24
 package.divider.vertical=0.837173579109063
22 25
 package.editor.height=538
23
-package.editor.width=968
24
-package.editor.x=59
26
+package.editor.width=699
27
+package.editor.x=102
25 28
 package.editor.y=23
26 29
 package.frame.height=709
27
-package.frame.width=1094
28
-package.numDependencies=4
30
+package.frame.width=825
31
+package.numDependencies=5
29 32
 package.numTargets=10
30 33
 package.showExtends=true
31 34
 package.showUses=true
@@ -40,68 +43,69 @@ target1.name=Factorial
40 43
 target1.showInterface=false
41 44
 target1.type=ClassTarget
42 45
 target1.width=80
43
-target1.x=160
44
-target1.y=10
46
+target1.x=280
47
+target1.y=210
45 48
 target10.height=50
46 49
 target10.name=IntegerPrinterTest
47 50
 target10.showInterface=false
48 51
 target10.type=UnitTestTargetJunit4
49 52
 target10.width=140
50
-target10.x=510
51
-target10.y=130
53
+target10.x=240
54
+target10.y=120
52 55
 target2.height=50
53 56
 target2.name=NormalizeAngle
54 57
 target2.showInterface=false
55 58
 target2.type=ClassTarget
56 59
 target2.width=120
57
-target2.x=70
58
-target2.y=70
60
+target2.x=470
61
+target2.y=30
59 62
 target3.height=50
60 63
 target3.name=IntegerPrinter
61 64
 target3.showInterface=false
62 65
 target3.type=ClassTarget
63 66
 target3.width=110
64
-target3.x=530
65
-target3.y=50
67
+target3.x=240
68
+target3.y=20
69
+target4.association=ShortCalculatorTest
66 70
 target4.height=50
67 71
 target4.name=ShortCalculator
68 72
 target4.showInterface=false
69 73
 target4.type=ClassTarget
70 74
 target4.width=120
71
-target4.x=130
72
-target4.y=130
75
+target4.x=40
76
+target4.y=200
73 77
 target5.height=50
74 78
 target5.name=LargestInteger
75 79
 target5.showInterface=false
76 80
 target5.type=ClassTarget
77 81
 target5.width=120
78
-target5.x=10
79
-target5.y=190
82
+target5.x=260
83
+target5.y=370
80 84
 target6.height=50
81 85
 target6.name=LargestIntegerTest
82 86
 target6.showInterface=false
83 87
 target6.type=UnitTestTargetJunit4
84 88
 target6.width=140
85
-target6.x=250
86
-target6.y=190
89
+target6.x=270
90
+target6.y=470
87 91
 target7.height=50
88 92
 target7.name=ShortCalculatorTest
89 93
 target7.showInterface=false
90
-target7.type=ClassTarget
91
-target7.width=150
92
-target7.x=10
93
-target7.y=250
94
+target7.type=UnitTestTargetJunit4
95
+target7.width=120
96
+target7.x=70
97
+target7.y=170
94 98
 target8.height=50
95 99
 target8.name=NormalizeAngleTest
96 100
 target8.showInterface=false
97 101
 target8.type=UnitTestTargetJunit4
98 102
 target8.width=150
99
-target8.x=10
100
-target8.y=310
103
+target8.x=470
104
+target8.y=150
101 105
 target9.height=50
102 106
 target9.name=FactorialTest
103 107
 target9.showInterface=false
104 108
 target9.type=UnitTestTargetJunit4
105 109
 target9.width=110
106
-target9.x=410
107
-target9.y=260
110
+target9.x=290
111
+target9.y=300