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