package bakatxt.core;

import java.util.Scanner;

public class BakaTxtMain {

    private static final String MESSAGE_WELCOME = "Welcome To BakaTxt!";
    private static final String MESSAGE_BYEBYE = "Bye bye!";
    private static final String MESSAGE_ENTER_COMMAND = "Please enter command: ";

    enum CommandType {
        ADD, DELETE, DISPLAY, EXIT, NULL;
    }

    private static Scanner _sc;
    private static BakaParser _parser;
    private static Database _database;
    private static String _filename;

    public BakaTxtMain() {
        // TODO this is kludge code - to be removed
        _filename = "mytestfile.txt";
        _sc = new Scanner(System.in);
        _parser = new BakaParser();
        _database = new Database(_filename);
    }

    public static void main(String[] args) {
        BakaTxtMain thisSession = new BakaTxtMain();

        System.out.println(MESSAGE_WELCOME);

        while (true) {
            System.out.print(MESSAGE_ENTER_COMMAND);
            String input = _sc.nextLine();
            String result = executeCommand(input);
            System.out.println(result);
        }
    }

    private static String executeCommand(String input) {
        String command = _parser.getCommand(input);
        CommandType commandType = CommandType.valueOf(command);

        String output = null;
        switch (commandType) {
            case ADD :
                Task toAdd = _parser.add(input);
                boolean isAdded = _database.add(toAdd);
                if (isAdded) {
                    // TODO something when added
                    output = toAdd.toDisplayString();
                } else {
                    // TODO error in adding
                }
                break;
            case DELETE :
                break;
            case DISPLAY :
                break;
            case EXIT :
                System.out.println(MESSAGE_BYEBYE);
                break;
            default :
        }

        return output;
    }
}

@@ -349,14 +349,8 @@
 EXIT
-, NULL
 ;%0A  
@@ -1716,32 +1716,33 @@
          break;%0A
+%0A
             case
@@ -1766,32 +1766,33 @@
          break;%0A
+%0A
             case
@@ -1817,32 +1817,33 @@
          break;%0A
+%0A
             case
@@ -1902,16 +1902,83 @@
 YEBYE);%0A
+                _database.close();%0A                System.exit(0);%0A
         
@@ -1992,16 +1992,17 @@
  break;%0A
+%0A
         

Add more information from BakaTxtMain_old