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