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