Allison Ziegler 6 anni fa
parent
commit
9219667550

BIN
Factorial.class Vedi File


+ 5
- 0
Factorial.ctxt Vedi File

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

@@ -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
FactorialTest.class Vedi File


+ 7
- 0
FactorialTest.ctxt Vedi File

@@ -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
IntegerPrinter.class Vedi File


+ 9
- 0
IntegerPrinter.ctxt Vedi File

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

@@ -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
IntegerPrinterTest.class Vedi File


+ 11
- 0
IntegerPrinterTest.ctxt Vedi File

@@ -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
LargestInteger.class Vedi File


+ 7
- 0
LargestInteger.ctxt Vedi File

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

@@ -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
LargestIntegerTest.class Vedi File


+ 9
- 0
LargestIntegerTest.ctxt Vedi File

@@ -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
Main.class Vedi File


+ 5
- 0
Main.ctxt Vedi File

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

@@ -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
NormalizeAngle.class Vedi File


+ 7
- 0
NormalizeAngle.ctxt Vedi File

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

@@ -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
NormalizeAngleTest.class Vedi File


+ 9
- 0
NormalizeAngleTest.ctxt Vedi File

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

@@ -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
ShortCalculator.class Vedi File


+ 15
- 0
ShortCalculator.ctxt Vedi File

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

@@ -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
ShortCalculatorTest.class Vedi File


+ 3
- 0
ShortCalculatorTest.ctxt Vedi File

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