title: Simple calculate using inheritance and Scanner how i handle these Exceptions?
body: <p>I'm trying to make a simple calculator using scanner and inheritance too, after i insert two numbers and operator i found this Exception </p>
  
  <p><strong>the Exception is :</strong></p>
  
  <pre><code>Exception in thread "main" java.util.InputMismatchException
  at java.util.Scanner.throwFor(Scanner.java:864)
  at java.util.Scanner.next(Scanner.java:1485)
  at java.util.Scanner.nextShort(Scanner.java:1987)
  at java.util.Scanner.nextShort(Scanner.java:1946)
  at calculator.simplecalc.&lt;init&gt;(simplecalc.java:18)
  at calculator.simplecalc_inhe.&lt;init&gt;(simplecalc_inhe.java:7)
  at calculator.Calculator.main(Calculator.java:6)
  </code></pre>
  
  <p>My Java Code: first class is <strong>Superclass</strong> it name is <strong>simplecalc.java</strong></p>
  
  <pre><code> package calculator;
   import java.util.Scanner;
  
   public class simplecalc {
  
      private int val1;
      private int val2;
      private Scanner sca;
      public char op;
      public int result;
  
      public simplecalc () 
      {
          sca = new Scanner(System.in);
          System.out.println("Enter the first number");
          val1 = sca.nextInt();
          System.out.println("Enter the Second number");
          val2 = sca.nextInt();
          System.out.println("choose an operator + or - or * or / ");
          op = (char) sca.nextShort();
          System.out.println(op);
      }
  
      /*use if operator not equal + or - */
      public char set_op()
      {
          op = (char) sca.nextShort();
          return op;
      }
  
  
      public int calsum()
      {
          return this.val1 + this.val2; 
      }
  
      public int calsub()
      {
          return this.val1 - this.val2; 
      }
  
      //i don't use setX and setX i write them because i use getX,Y
  
      /* public void setX(int x)
      {
          this.val1 = x;
      }
      public void setY(int y)
      {
          this.val2 = y;
      } */
  
      public int getX()
      {
          return this.val1;
      }
      public int getY()
      {
          return this.val2;
      }
  
  }
  </code></pre>
  
  <p><em>Subclass</em>: <strong>simplecalc_inhe.java</strong></p>
  
  <pre><code>package calculator;
  
  public class simplecalc_inhe extends simplecalc {
  
      public simplecalc_inhe()
      {
          super();
      }
  
  
      public int mult()
      {
          return this.getX() * this.getY();
      }
  
       public int div()
      {
          int z = this.getY();
          if(z == 0){
              return 0;
          }
          return this.getX() / z;
      }
  }
  </code></pre>
  
  <p><em>Main-class</em>: <strong>Calculator.java</strong></p>
  
  <pre><code>package calculator;
  
  public class Calculator {
  
      public static void main(String[] args) {
          simplecalc_inhe cal = new simplecalc_inhe();
  
          if (cal.op != '+' || cal.op != '-' || cal.op != '*' || cal.op != '/' )
          {
              System.out.println("You must enter a vaild operator");
              cal.set_op(); //to set operator 
  
          } else {
  
              if(cal.op == '+' ) {
                  cal.result = cal.calsum();
                  System.out.println(cal.result);
  
              }else if(cal.op == '-') {
                  cal.result = cal.calsub();
                  System.out.println(cal.result);
  
              }else if(cal.op == '*') {
                  cal.result = cal.mult();
                  System.out.println(cal.result);
  
              }else if(cal.op == '/') {
                  cal.result = cal.div();
                  System.out.println(cal.result);
              }
          }
      }
  }
  </code></pre>
  
  <p>I hope i explained that error well with most of details, Thank You.  </p>