package ru.szhernovoy.control;

import ru.szhernovoy.model.ErrorInput;

/**
 * Created by admin on 20.08.2016.
 */
public class ValidateIO extends ConsoleIO {

    /**
     * simple ask
     * @param question
     * @return
     * @throws ErrorInput
     */
    public boolean ask(String question)  {

        boolean correctInput = false;
        boolean result = false;
        do{
            try {
                result =  super.ask(question);
                correctInput = true;
            } catch (ErrorInput errorInput) {
                System.out.println("Uncorrect input - try again...");
            }
        }while(!correctInput);
        return result;
    }

    /**
     * Ask on range value
     * @param question
     * @param range
     * @return
     * @throws ErrorInput
     */
    public int ask(String question, int[] range) {

        boolean correctInput = false;
        int result = 0;
        do{
            try {
                result =  super.ask(question,range)-1;
                correctInput = true;
            } catch (ErrorInput | NumberFormatException exc) {
                System.out.println("Uncorrect input - try again...");
            }
        }while(!correctInput);
        return result;

    }
}

@@ -65,16 +65,58 @@
 Input;%0A%0A
+import java.util.InputMismatchException;%0A%0A
 /**%0A * C
@@ -1106,16 +1106,17 @@
 orInput 
+ 
 %7C Number
@@ -1213,32 +1213,153 @@
 );%0A            %7D
+catch (InputMismatchException  exc)%7B%0A                System.out.println(%22Uncorrect input - try again...%22);%0A            %7D%0A
 %0A        %7Dwhile(

update tic