Allison Ziegler 6 gadus atpakaļ
vecāks
revīzija
9219667550

Binārs
Factorial.class Parādīt failu


+ 5
- 0
Factorial.ctxt Parādīt failu

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

+ 8
- 1
Factorial.java Parādīt failu

@@ -6,7 +6,14 @@ import java.math.BigInteger;
6 6
 public class Factorial {
7 7
 
8 8
     public BigInteger factorialOf(Integer value){
9
-        return null;
9
+        BigInteger big = BigInteger.valueOf(1);
10
+
11
+        for (int i = 1; i <= value; i++) {
12
+            BigInteger x = BigInteger.valueOf(i);
13
+            big = big.multiply(x);
14
+        }
15
+        
16
+        return big;
10 17
     }
11 18
 
12 19
 }

Binārs
FactorialTest.class Parādīt failu


+ 7
- 0
FactorialTest.ctxt Parādīt failu

@@ -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ārs
IntegerPrinter.class Parādīt failu


+ 9
- 0
IntegerPrinter.ctxt Parādīt failu

@@ -0,0 +1,9 @@
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
+numComments=4

+ 13
- 5
IntegerPrinter.java Parādīt failu

@@ -4,18 +4,26 @@
4 4
 public class IntegerPrinter {
5 5
 
6 6
     public String printIntegerAsBinary(int value){
7
-        return null;
7
+        String bin = Integer.toBinaryString(value);
8
+        System.out.println(bin);
9
+        return bin;
8 10
     }
9 11
 
10 12
     public String printIntegerAsOctal(int value){
11
-        return null;
13
+        String octal = Integer.toOctalString(value);
14
+        System.out.println(octal);
15
+        return octal;
12 16
     }
13 17
 
14 18
     public String printIntegerAsHexadecimal(int value){
15
-        return null;
19
+        String hex = Integer.toHexString(value);
20
+        System.out.println(hex);
21
+        return hex;
16 22
     }
17 23
 
18
-    public static void main(String[] args){
24
+    // public static void main(String[] args){
25
+        //I don't think it makes sense to have a main method here? Commented
26
+        //out to be safe.
19 27
 
20
-    }
28
+    // }
21 29
 }

Binārs
IntegerPrinterTest.class Parādīt failu


+ 11
- 0
IntegerPrinterTest.ctxt Parādīt failu

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

Binārs
LargestInteger.class Parādīt failu


+ 7
- 0
LargestInteger.ctxt Parādīt failu

@@ -0,0 +1,7 @@
1
+#BlueJ class context
2
+comment0.target=LargestInteger
3
+comment1.params=integers
4
+comment1.target=java.lang.Integer\ findLargestNumberUsingConditional(java.lang.Integer[])
5
+comment2.params=integers
6
+comment2.target=java.lang.Integer\ findLargestNumberUsingMathMax(java.lang.Integer[])
7
+numComments=3

+ 11
- 2
LargestInteger.java Parādīt failu

@@ -4,10 +4,19 @@
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
+            largest = integers[i] > largest ? integers[i] : largest;
10
+        }
11
+        
12
+        return largest;
8 13
     }
9 14
 
10 15
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
11
-        return null;
16
+        int largest = 0;
17
+        for (int i = 1; i < integers.length; i++) {
18
+            largest = Math.max(integers[i], integers[i-1]);
19
+        }
20
+        return largest;
12 21
     }
13 22
 }

Binārs
LargestIntegerTest.class Parādīt failu


+ 9
- 0
LargestIntegerTest.ctxt Parādīt failu

@@ -0,0 +1,9 @@
1
+#BlueJ class context
2
+comment0.target=LargestIntegerTest
3
+comment1.params=
4
+comment1.target=void\ setUp()
5
+comment2.params=
6
+comment2.target=void\ findLargestNumberUsingConditionalTest()
7
+comment3.params=
8
+comment3.target=void\ findLargestNumberUsingMathMaxTest()
9
+numComments=4

Binārs
Main.class Parādīt failu


+ 5
- 0
Main.ctxt Parādīt failu

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

+ 29
- 0
Main.java Parādīt failu

@@ -0,0 +1,29 @@
1
+
2
+/**
3
+ * 
4
+ */
5
+
6
+import java.util.Scanner;
7
+
8
+public class Main
9
+{
10
+    public static void main(String[] args){
11
+        Scanner s = new Scanner(System.in);
12
+        
13
+        System.out.println("Welcome to this short calculator!");
14
+        System.out.println("Please enter two numbers between 0 and 65535.");
15
+        System.out.print("First number: ");
16
+        short x = (short) s.nextInt();
17
+        System.out.print("Second number: ");
18
+        short y = (short) s.nextInt();
19
+        ShortCalculator calc = new ShortCalculator(x, y);
20
+        
21
+        System.out.println("Sum = " + calc.getSum());
22
+        System.out.println("Difference = " + calc.getDifference());
23
+        System.out.println("Quotient = " + calc.getQuotient());
24
+        System.out.println("Remainder = " + calc.getRemainder());
25
+        
26
+        System.out.println("Thank you for using this short calculator!");
27
+        
28
+    }
29
+}

Binārs
NormalizeAngle.class Parādīt failu


+ 7
- 0
NormalizeAngle.ctxt Parādīt failu

@@ -0,0 +1,7 @@
1
+#BlueJ class context
2
+comment0.target=NormalizeAngle
3
+comment1.params=angle
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
+numComments=3

+ 18
- 4
NormalizeAngle.java Parādīt failu

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

Binārs
NormalizeAngleTest.class Parādīt failu


+ 9
- 0
NormalizeAngleTest.ctxt Parādīt failu

@@ -0,0 +1,9 @@
1
+#BlueJ class context
2
+comment0.target=NormalizeAngleTest
3
+comment1.params=
4
+comment1.target=void\ setUp()
5
+comment2.params=
6
+comment2.target=void\ normalizeValueUsingModuloTest()
7
+comment3.params=
8
+comment3.target=void\ normalizeValueUsingFloorModTest()
9
+numComments=4

+ 10
- 0
README.TXT Parādīt failu

@@ -0,0 +1,10 @@
1
+Allison Ziegler
2
+5/24/2018
3
+Basic Computations Lab
4
+
5
+Tests pass for NormalizeAngle, LargestInteger, and IntegerPrinter!
6
+
7
+Also, there weren't a whole lot of instructions for ShortCalculator, so I made
8
+a Main class with a Main method. Running it opens a little console UI. It 
9
+prompts the user to enter two numbers. It truncates any input that's too high,
10
+and then allows any weird math to happen with the shorts.

Binārs
ShortCalculator.class Parādīt failu


+ 15
- 0
ShortCalculator.ctxt Parādīt failu

@@ -0,0 +1,15 @@
1
+#BlueJ class context
2
+comment0.target=ShortCalculator
3
+comment1.params=x\ y
4
+comment1.target=ShortCalculator(short,\ short)
5
+comment2.params=
6
+comment2.target=short\ getSum()
7
+comment3.params=
8
+comment3.target=short\ getDifference()
9
+comment4.params=
10
+comment4.target=short\ getProduct()
11
+comment5.params=
12
+comment5.target=short\ getQuotient()
13
+comment6.params=
14
+comment6.target=short\ getRemainder()
15
+numComments=7

+ 28
- 0
ShortCalculator.java Parādīt failu

@@ -2,4 +2,32 @@
2 2
 
3 3
 
4 4
 public class ShortCalculator {
5
+    short x;
6
+    short y;
7
+    
8
+    public ShortCalculator (short x, short y){
9
+        this.x = x;
10
+        this.y = y;
11
+    }
12
+    
13
+    public short getSum(){
14
+        return (short) (x + y);
15
+    }
16
+    
17
+    public short getDifference() {
18
+        return (short) (x - y);
19
+    }
20
+    
21
+    public short getProduct() {
22
+        return (short) (x * y);
23
+    }
24
+    
25
+    public short getQuotient() {
26
+        return (short) (x / y);
27
+    }
28
+    
29
+    public short getRemainder() {
30
+        return (short) (x % y);
31
+    }
32
+    
5 33
 }

Binārs
ShortCalculatorTest.class Parādīt failu


+ 3
- 0
ShortCalculatorTest.ctxt Parādīt failu

@@ -0,0 +1,3 @@
1
+#BlueJ class context
2
+comment0.target=ShortCalculatorTest
3
+numComments=1