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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.redhat.training;
 
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 
public class TodoMap {
 
    Map<Integer, TodoItem> todoMap;
    static Integer count = 0;
    TodoItem item;
    Scanner scn;
 
    public TodoMap() {
        this.todoMap = new HashMap<Integer,TodoItem>();
    }
 
    public void addTodo() {
        String ans = "Y";
        do {
 
            item = new TodoItem();
            count++;
            scn = new Scanner(System.in);
            System.out.println("Enter item description:");
            item.setItem(scn.nextLine());
            System.out.println("Is todo item completed? [Y/N]:");
            String state = scn.nextLine();
            String status = "";
 
            if (state.toUpperCase().charAt(0) == 'Y')
                status = Status.COMPLETED.toString();
            else
                status = Status.PENDING.toString();
 
            item.setStatus(status);
            todoMap.put(new Integer(count), item);
            System.out.println("Do you want to add more items[Y/N]");
            ans = scn.next().toUpperCase();
 
        } while(ans.equalsIgnoreCase("Y"));
 
    }
 
    public void printTodo() {
        System.out.println("---- There are " + todoMap.size() + " items in the list ----");
        for (Integer key : todoMap.keySet()) {
            System.out
                    .println(key + " - " + todoMap.get(key).getItem() + " - " + todoMap.get(key).getStatus());
        }
 
    }
 
    public void completeTodo(int key) {
 
        if (todoMap.get(key).getStatus().equals(Status.COMPLETED.toString()))
        {
            System.out.println("This item is already COMPLETED.\n");
        }
        else
        {
            item = new TodoItem();
            String i = todoMap.get(key).getItem();
            item.setItem(i);
            item.setStatus(Status.COMPLETED.toString());
            todoMap.replace(key, item);
            System.out.println("Marked item #" +key+ " as COMPLETE.\n");
            printTodo();
        }
    }
 
 
    public void deleteTodo(int id) {
 
        System.out.println("Enter id of item to be deleted");
        scn = new Scanner(System.in);
        todoMap.remove(id);
        System.out.println("Item removed\n");
 
    }
 
    public void findItemTodo(int id) {
        System.out.println("\n");
        System.out.println(id + " - " + todoMap.get(id).getItem() + " - " + todoMap.get(id).getStatus());
 
    }
 
}