public class Calculator {

  public static void main(String[] args) {
    presentMenu();
    processOperation();
  }

  private static void presentMenu() {
    // post: Menu appears on the screen.
    System.out.println("Enter 0 to quit");
    System.out.println("Enter 1 to add");
    System.out.println("Enter 2 to subtract");
    System.out.println("Enter 3 to multiply");
    System.out.println("Enter 4 to divide");
    System.out.println("Enter 5 to negate");
  }

  private static void processOperation() {

    int reply = IOUtil.readInt();
    assert (0 <= reply && reply <= 5) : "A number between 0 and 5 must be entered.";

    switch (reply) {
      case 0:
        return;
      case 1:
      case 2:
      case 3:
      case 4:
        processTwoArguments(reply);
        return;
      case 5:
        processOneArgument(reply);
    }
  }

  private static void processTwoArguments(int reply) {
    assert (1 <= reply && reply <= 4);
    System.out.print("Please enter your two integers -> ");
    int x = IOUtil.readInt();
    int y = IOUtil.readInt();

    int result;
    String op;

    switch (reply) {
      case 1:
        result = x + y;
        op = " + ";
        break;
      case 2:
        result = x - y;
        op = " - ";
        break;
      case 3:
        result = x * y;
        op = " * ";
        break;
      case 4:
        result = x / y;
        op = " / ";
        break;
      default:
        return; // should be impossible!
    }
    System.out.println(x + op + y + " = " + result);
  }

  private static void processOneArgument(int reply) {
    System.out.print("Please enter your integer -> ");
    int x = IOUtil.readInt();
    System.out.println("-(" + x + ") = " + -x);
  }

}