Allison Ziegler před 6 roky
rodič
revize
9219667550

binární
Factorial.class Zobrazit soubor


+ 5
- 0
Factorial.ctxt Zobrazit soubor

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 Zobrazit soubor

6
 public class Factorial {
6
 public class Factorial {
7
 
7
 
8
     public BigInteger factorialOf(Integer value){
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ární
FactorialTest.class Zobrazit soubor


+ 7
- 0
FactorialTest.ctxt Zobrazit soubor

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ární
IntegerPrinter.class Zobrazit soubor


+ 9
- 0
IntegerPrinter.ctxt Zobrazit soubor

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 Zobrazit soubor

4
 public class IntegerPrinter {
4
 public class IntegerPrinter {
5
 
5
 
6
     public String printIntegerAsBinary(int value){
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
     public String printIntegerAsOctal(int value){
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
     public String printIntegerAsHexadecimal(int value){
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ární
IntegerPrinterTest.class Zobrazit soubor


+ 11
- 0
IntegerPrinterTest.ctxt Zobrazit soubor

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ární
LargestInteger.class Zobrazit soubor


+ 7
- 0
LargestInteger.ctxt Zobrazit soubor

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 Zobrazit soubor

4
 public class LargestInteger {
4
 public class LargestInteger {
5
 
5
 
6
     public Integer findLargestNumberUsingConditional(Integer[] integers){
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
     public Integer findLargestNumberUsingMathMax(Integer[] integers){
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ární
LargestIntegerTest.class Zobrazit soubor


+ 9
- 0
LargestIntegerTest.ctxt Zobrazit soubor

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ární
Main.class Zobrazit soubor


+ 5
- 0
Main.ctxt Zobrazit soubor

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 Zobrazit soubor

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ární
NormalizeAngle.class Zobrazit soubor


+ 7
- 0
NormalizeAngle.ctxt Zobrazit soubor

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 Zobrazit soubor

4
 public class NormalizeAngle {
4
 public class NormalizeAngle {
5
 
5
 
6
     public Integer normalizeValueUsingModulo(Integer angle){
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
     public Integer normalizeValueUsingFloorMod(Integer integer){
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ární
NormalizeAngleTest.class Zobrazit soubor


+ 9
- 0
NormalizeAngleTest.ctxt Zobrazit soubor

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 Zobrazit soubor

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ární
ShortCalculator.class Zobrazit soubor


+ 15
- 0
ShortCalculator.ctxt Zobrazit soubor

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 Zobrazit soubor

2
 
2
 
3
 
3
 
4
 public class ShortCalculator {
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ární
ShortCalculatorTest.class Zobrazit soubor


+ 3
- 0
ShortCalculatorTest.ctxt Zobrazit soubor

1
+#BlueJ class context
2
+comment0.target=ShortCalculatorTest
3
+numComments=1