Browse Source

lab submission

Rachelle 6 years ago
parent
commit
7a7194d267

BIN
LargestInteger.class View File


+ 8
- 7
LargestInteger.java View File

@@ -4,13 +4,14 @@
4 4
 public class LargestInteger {
5 5
 
6 6
     public Integer findLargestNumberUsingConditional(Integer[] integers){
7
-        //loop will through
8
-        
9
-        
10
-        return null;
11
-    }
12
-
7
+        Integer largerInteger = (integers[0]<integers[1]) ? integers[1]:integers[0];
8
+        Integer largestInteger = (largerInteger<integers[2]) ? integers[2]:largerInteger;
9
+        return largestInteger;
10
+    }  
11
+    
13 12
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
14
-        return null;
13
+        Integer largerInteger = Math.max(integers[0],integers[1]);
14
+        Integer largestInteger = Math.max(integers[1],integers[2]);
15
+        return largestInteger;
15 16
     }
16 17
 }

BIN
NormalizeAngle.class View File


+ 7
- 5
NormalizeAngle.ctxt View File

@@ -2,8 +2,10 @@
2 2
 comment0.target=NormalizeAngle
3 3
 comment1.params=angle
4 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
5
+comment2.params=angle
6
+comment2.target=java.lang.Integer\ mod360(java.lang.Integer)
7
+comment3.params=integer
8
+comment3.target=java.lang.Integer\ normalizeValueUsingFloorMod(java.lang.Integer)
9
+comment4.params=args
10
+comment4.target=void\ main(java.lang.String[])
11
+numComments=5

+ 13
- 2
NormalizeAngle.java View File

@@ -4,11 +4,22 @@
4 4
 public class NormalizeAngle {
5 5
 
6 6
     public Integer normalizeValueUsingModulo(Integer angle){
7
-        return 0;
7
+        Integer normalizedAngle = mod360(angle);
8
+        if(normalizedAngle<0){
9
+            normalizedAngle = normalizedAngle * (-1);
10
+        }
11
+        return normalizedAngle;
12
+    }
13
+    
14
+    public Integer mod360 (Integer angle){
15
+        Integer modulus360 = angle%360;
16
+        return modulus360;
8 17
     }
9 18
 
10 19
     public Integer normalizeValueUsingFloorMod(Integer integer){
11
-        return 0;
20
+        int x = Math.floorMod(integer, 360);
21
+        
22
+        return x;
12 23
     }
13 24
 
14 25
     public static void main(String[] args){

BIN
ShortCalculator.class View File


+ 11
- 1
ShortCalculator.ctxt View File

@@ -1,3 +1,13 @@
1 1
 #BlueJ class context
2 2
 comment0.target=ShortCalculator
3
-numComments=1
3
+comment1.params=x\ y
4
+comment1.target=short\ sum(short,\ short)
5
+comment2.params=x\ y
6
+comment2.target=short\ difference(short,\ short)
7
+comment3.params=x\ y
8
+comment3.target=short\ product(short,\ short)
9
+comment4.params=x\ y
10
+comment4.target=short\ quotient(short,\ short)
11
+comment5.params=x\ y
12
+comment5.target=short\ remainder(short,\ short)
13
+numComments=6

+ 15
- 0
ShortCalculator.java View File

@@ -2,4 +2,19 @@
2 2
 
3 3
 
4 4
 public class ShortCalculator {
5
+    public short sum(short x,short y){
6
+        return (short)(x + y);
7
+    }
8
+    public short difference(short x, short y){
9
+        return (short)(x-y);
10
+    }
11
+    public short product(short x, short y){
12
+        return (short)(x*y);
13
+    }
14
+    public short quotient(short x, short y){
15
+        return (short)(x/y);
16
+    }
17
+    public short remainder(short x, short y){
18
+        return (short)(x%y);
19
+    }
5 20
 }

BIN
ShortCalculatorTest.class View File


+ 11
- 1
ShortCalculatorTest.ctxt View File

@@ -1,3 +1,13 @@
1 1
 #BlueJ class context
2 2
 comment0.target=ShortCalculatorTest
3
-numComments=1
3
+comment1.params=
4
+comment1.target=void\ sumTest()
5
+comment2.params=
6
+comment2.target=void\ differenceTest()
7
+comment3.params=
8
+comment3.target=void\ productTest()
9
+comment4.params=
10
+comment4.target=void\ quotientTest()
11
+comment5.params=
12
+comment5.target=void\ remainderTest()
13
+numComments=6

+ 35
- 2
ShortCalculatorTest.java View File

@@ -1,5 +1,38 @@
1
- 
2 1
 
2
+import org.junit.Assert;
3
+import org.junit.Test;
3 4
 
4
-public class ShortCalculatorTest {
5
+public class ShortCalculatorTest 
6
+{   
7
+    ShortCalculator test = new ShortCalculator();
8
+    @Test
9
+    public void sumTest(){
10
+        short expected = (short)131070;
11
+        short actual = test.sum((short)65535,(short)65535);
12
+        Assert.assertEquals(expected,actual);
13
+    }
14
+    @Test
15
+    public void differenceTest(){
16
+        short expected = 679;
17
+        short actual = test.difference((short)700,(short)21);
18
+        Assert.assertEquals(expected,actual);
19
+    }
20
+    @Test
21
+    public void productTest(){
22
+        short expected = 6000;
23
+        short actual = test.product((short)200,(short)30);
24
+        Assert.assertEquals(expected,actual);    
25
+    }
26
+    @Test
27
+    public void quotientTest(){
28
+        short expected = 600;
29
+        short actual = test.quotient((short)18000,(short)30);
30
+        Assert.assertEquals(expected,actual);
31
+    }
32
+    @Test
33
+    public void remainderTest(){
34
+        short expected = 1;
35
+        short actual = test.remainder((short)18001,(short)18000);
36
+        Assert.assertEquals(expected,actual);
37
+    }
5 38
 }

+ 11
- 8
package.bluej View File

@@ -5,15 +5,18 @@ dependency1.type=UsesDependency
5 5
 dependency2.from=FactorialTest
6 6
 dependency2.to=Factorial
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=LargestIntegerTest
9
-dependency3.to=LargestInteger
8
+dependency3.from=NormalizeAngleTest
9
+dependency3.to=NormalizeAngle
10 10
 dependency3.type=UsesDependency
11
-dependency4.from=NormalizeAngleTest
12
-dependency4.to=NormalizeAngle
11
+dependency4.from=LargestIntegerTest
12
+dependency4.to=LargestInteger
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=28
19
+editor.fx.0.x=645
17 20
 editor.fx.0.y=23
18 21
 objectbench.height=98
19 22
 objectbench.width=637
@@ -21,11 +24,11 @@ package.divider.horizontal=0.5996275605214153
21 24
 package.divider.vertical=0.8387096774193549
22 25
 package.editor.height=539
23 26
 package.editor.width=968
24
-package.editor.x=296
27
+package.editor.x=186
25 28
 package.editor.y=23
26 29
 package.frame.height=709
27 30
 package.frame.width=1094
28
-package.numDependencies=4
31
+package.numDependencies=5
29 32
 package.numTargets=10
30 33
 package.showExtends=true
31 34
 package.showUses=true
@@ -87,7 +90,7 @@ target6.y=190
87 90
 target7.height=50
88 91
 target7.name=ShortCalculatorTest
89 92
 target7.showInterface=false
90
-target7.type=ClassTarget
93
+target7.type=UnitTestTargetJunit4
91 94
 target7.width=150
92 95
 target7.x=240
93 96
 target7.y=50