Explorar el Código

calc revised again

John Kim hace 6 años
padre
commit
6d0c01cddf
Se han modificado 4 ficheros con 43 adiciones y 34 borrados
  1. BIN
      ShortCalculator.class
  2. 13
    11
      ShortCalculator.ctxt
  3. 22
    15
      ShortCalculator.java
  4. 8
    8
      package.bluej

BIN
ShortCalculator.class Ver fichero


+ 13
- 11
ShortCalculator.ctxt Ver fichero

@@ -1,17 +1,19 @@
1 1
 #BlueJ class context
2 2
 comment0.target=ShortCalculator
3
-comment1.params=args
4
-comment1.target=void\ main(java.lang.String[])
5
-comment2.params=
6
-comment2.target=short\ sum()
3
+comment1.params=x\ y
4
+comment1.target=ShortCalculator(int,\ int)
5
+comment2.params=args
6
+comment2.target=void\ main(java.lang.String[])
7 7
 comment3.params=
8
-comment3.target=short\ difference()
8
+comment3.target=short\ sum()
9 9
 comment4.params=
10
-comment4.target=short\ product()
10
+comment4.target=short\ difference()
11 11
 comment5.params=
12
-comment5.target=short\ quotient()
12
+comment5.target=short\ product()
13 13
 comment6.params=
14
-comment6.target=short\ remainder()
15
-comment7.params=operation\ value
16
-comment7.target=void\ printLine(java.lang.String,\ short)
17
-numComments=8
14
+comment6.target=short\ quotient()
15
+comment7.params=
16
+comment7.target=short\ remainder()
17
+comment8.params=operation\ value
18
+comment8.target=void\ printLine(java.lang.String,\ short)
19
+numComments=9

+ 22
- 15
ShortCalculator.java Ver fichero

@@ -2,45 +2,52 @@
2 2
 import java.util.Scanner;
3 3
 
4 4
 public class ShortCalculator {
5
-    private static int x;
6
-    private static int y;
5
+    private int x;
6
+    private int y;
7
+    
8
+    public ShortCalculator(int x, int y) {
9
+        this.x = x;
10
+        this.y = y;
11
+    }
12
+    
7 13
     public static void main(String[] args) {
8 14
         Scanner reader = new Scanner(System.in);
9 15
 
10 16
         System.out.println("Enter two numbers between 0 and 65535");
11 17
         System.out.println("Input the first number:"); 
12
-        x = (short) reader.nextInt();
18
+        int n1 = reader.nextInt();
13 19
         System.out.println("Input the second number:");
14
-        y = (short) reader.nextInt();
20
+        int n2 = reader.nextInt();
21
+        ShortCalculator calc = new ShortCalculator(n1, n2);
15 22
         
16
-        ShortCalculator.printLine("Sum", ShortCalculator.sum());
17
-        ShortCalculator.printLine("Difference", ShortCalculator.difference());
18
-        ShortCalculator.printLine("Product", ShortCalculator.product());
19
-        ShortCalculator.printLine("Quotient", ShortCalculator.quotient());
20
-        ShortCalculator.printLine("Remainder", ShortCalculator.remainder());
23
+        calc.printLine("Sum", calc.sum());
24
+        calc.printLine("Difference", calc.difference());
25
+        calc.printLine("Product", calc.product());
26
+        calc.printLine("Quotient", calc.quotient());
27
+        calc.printLine("Remainder", calc.remainder());
21 28
     }
22 29
     
23
-    public static short sum() {
30
+    public short sum() {
24 31
         return (short) (x + y);
25 32
     }
26 33
     
27
-    public static short difference() {
34
+    public short difference() {
28 35
         return (short) (x / y);
29 36
     }
30 37
     
31
-    public static short product() {
38
+    public short product() {
32 39
         return (short) (x * y);
33 40
     }
34 41
     
35
-    public static short quotient() {
42
+    public short quotient() {
36 43
         return (short) (x / y);
37 44
     }
38 45
     
39
-    public static short remainder() {
46
+    public short remainder() {
40 47
         return (short) (x % y);
41 48
     }
42 49
     
43
-    public static void printLine(String operation, short value) {
50
+    public void printLine(String operation, short value) {
44 51
         System.out.println(operation + ": " + value); 
45 52
     }
46 53
 }

+ 8
- 8
package.bluej Ver fichero

@@ -2,19 +2,19 @@
2 2
 dependency1.from=LargestIntegerTest
3 3
 dependency1.to=LargestInteger
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=NormalizeAngleTest
6
-dependency2.to=NormalizeAngle
5
+dependency2.from=FactorialTest
6
+dependency2.to=Factorial
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=FactorialTest
9
-dependency3.to=Factorial
8
+dependency3.from=IntegerPrinterTest
9
+dependency3.to=IntegerPrinter
10 10
 dependency3.type=UsesDependency
11
-dependency4.from=IntegerPrinterTest
12
-dependency4.to=IntegerPrinter
11
+dependency4.from=NormalizeAngleTest
12
+dependency4.to=NormalizeAngle
13 13
 dependency4.type=UsesDependency
14 14
 editor.fx.0.height=722
15 15
 editor.fx.0.width=800
16
-editor.fx.0.x=1048
17
-editor.fx.0.y=298
16
+editor.fx.0.x=592
17
+editor.fx.0.y=316
18 18
 objectbench.height=101
19 19
 objectbench.width=653
20 20
 package.divider.horizontal=0.6