ShortCalculator.java 1.3KB

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