Ravi Srinivasan
2018-09-06 1b26cc8d09cd5da97f80100ca2435ce296838685
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.redhat.training;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class TestTodoMap {
    public static void main(String[] args) {
        TodoMap testMap=new TodoMap();
 
        boolean timeToQuit = false;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        do {
            try {
                timeToQuit = executeMenu(in, testMap);
            } catch (IOException e) {
                System.out.println("Could not read the input");
            }
        } while (!timeToQuit);
 
    }
 
    public static boolean executeMenu(BufferedReader in, TodoMap todo) throws IOException {
 
        String action;
        int id;
 
        System.out.println("\n\n[N]ew | [C]omplete | [R]ead | [D]elete | [L]ist | [Q]uit: ");
        action = in.readLine();
        if ((action.length() == 0) || action.toUpperCase().charAt(0) == 'Q') {
            return true;
        }
 
        switch (action.toUpperCase().charAt(0)) {
        // Create a new todo record
        case 'N':
            todo.addTodo();
            System.out.println("Successfully added new todo item: ");
            break;
 
        // Display an todo record
        case 'R':
            System.out.println("Enter int value for item id: ");
            id = new Integer(in.readLine().trim());
            todo.findItemTodo(id);
            break;
 
        // Mark an existing task as completed
        case 'C':
            System.out.println("Enter int value for item id: ");
            id = new Integer(in.readLine().trim());
            todo.completeTodo(id);
            break;
 
 
        // Delete an todo record
        case 'D':
            System.out.println("Enter int value for item id: ");
            id = new Integer(in.readLine().trim());
            todo.deleteTodo(id);
            System.out.println("Deleted item " + id);
            break;
 
        // Display a list (Read the records) of todo
        case 'L':
            todo.printTodo();
            break;
        }
 
        return false;
    }
 
    }