title: Error checking for user input
body: <p>I have a class that asks the user what type of truck they want. I need to know a way to do error checking so that if they enter something besides "1" or "2" that it tells them that it is an invalid option.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>public class InheritanceTUI {
  
      private int weight;
      private String flavors;
      private Scanner scan = new Scanner(System.in);
      private String truckType;
  
  
      public void run() {
          System.out.println("Type \"1\" if you want a generic truck" + "\n" + "Type \"2\" if you want an Ice Cream Truck");
          this.truckType = this.scan.nextLine();
  
          if (this.truckType.equals("1")) {
              System.out.println("You have chosen a generic truck!");
              System.out.println("Type in what weight (in pounds) you want your truck to be: ");
              String stringWeight = this.scan.nextLine();
              this.weight = Integer.parseInt(stringWeight);
              System.out.println("Your truck has a weight of " + this.weight + " pounds");
          }
  
          if (this.truckType.equals("2")) {
              System.out.println("You have chosen an Ice Cream Truck! " + this.truckType);
              System.out.println("Type in what weight (in pounds) that you want your ice cream truck to be: ");
              String stringWeight = this.scan.nextLine();
              this.weight = Integer.parseInt(stringWeight);
              System.out.println("You have entered a weight of " + this.weight + " pounds");
              System.out.println("What flavors do you want in your ice cream truck?");
              this.flavors = this.scan.nextLine();
              System.out.println("Your ice cream truck has a weight of " + this.weight + " pounds and contains " + this.flavors + " flavor(s)");
          }
      }
  }
  </code></pre>