package ru.sbulygin.start;


import ru.sbulygin.templates.BaseAction;

/**
 * Class StartUI.
 *
 * @author ru.sbulygin.start.
 * @since 06.02.2017.
 * @version 1.0.
 */
public class StartUI {

    /**
     * The item field.
     */
    private Input input;

    /**
     * The item field.
     */
    private Tracker tracker;

    /**
     * Constructor of StartUI class.
     * @param input Input input.
     * @param tracker Tracker tracker.
     */
    public StartUI(Input input, Tracker tracker) {
        this.input = input;
        this.tracker = tracker;
    }

    /**
     * Initialization method of program.
     */
    public void init() {
        MenuTracker menu = new MenuTracker(this.input, tracker);

        int[] ranges = new int[]{0, 1, 2, 3, 4, 5, 6, 7};

        menu.fillActions();

        int exitActionKey = 7;

        UserAction exitAction = new BaseAction(exitActionKey, "Exit program") {

            @Override
            public void execute(Input input, Tracker tracker) {
                System.exit(0);
            }
        };

        menu.addAction(exitAction);

        do {
            menu.show();
            menu.select(input.ask("Select: ", ranges));
        } while (!"y".equals(this.input.ask("Exit? (y/n): ")));
    }
    /**
     * The entry point of the program.
     * @param args arguments from command line.
     */
    public static void main(String[] args) {
        Input input = new ValidateInput();
        Tracker tracker = new Tracker();
        new StartUI(input, tracker).init();
    }
}

@@ -908,24 +908,67 @@
 rogram%22) %7B%0A%0A
+            private boolean exit = false;%0A%0A
             
@@ -977,16 +977,16 @@
 verride%0A
-
         
@@ -1045,40 +1045,8 @@
 ) %7B%0A
-                System.exit(0);%0A
     
@@ -1194,24 +1194,228 @@
 , ranges));%0A
+            if (exitActionKey == 7) %7B%0A                String answer = input.ask(%22Are you sure? y/n: %22);%0A                if(answer.equals(%22y%22)) %7B%0A                    break;%0A                %7D%0A            %7D%0A
         %7D wh
@@ -1462,24 +1462,25 @@
 y/n): %22)));%0A
+%0A
     %7D%0A    /*

correct Exit method