-
Notifications
You must be signed in to change notification settings - Fork 1
/
List.java
84 lines (76 loc) · 1.71 KB
/
List.java
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
import java.util.HashMap;
import java.util.Scanner;
/*
class Item{
String title;
boolean completed;
Item(String x, boolean y){
this.title = x;
this.completed = y;
}
public void finished(boolean status){
this.completed = status;
}
public String getName(){
return this.title;
}
}*/
public class List{
public static void main(String[] args){
//Initialise variables
boolean leaving = true;
HashMap<String, Boolean> tasks = new HashMap<String, Boolean>();
//Objects and functions
Scanner ask = new Scanner(System.in);
//Main loop
while (leaving){
//Show options
System.out.println("1) Create item");
System.out.println("2) Read items");
System.out.println("3) Update item");
System.out.println("4) Delete item");
System.out.println("q) Quit");
//Gather input
System.out.print("Enter option: ");
String option = ask.nextLine();
switch (option){
//Create
case "1":
System.out.print("Name of item: ");
String name = ask.nextLine();
tasks.put(name, false);
System.out.println("Item created!");
break;
//Read
case "2":
for (String i : tasks.keySet()){
if (tasks.get(i)){
System.out.println("+ "+i);
}else{
System.out.println("- "+i);
}
}
break;
//Update
case "3":
System.out.print("Complated item: ");
String target = ask.nextLine();
tasks.put(target, true);
System.out.println("Item updated!");
break;
//Delete
case "4":
System.out.print("Target item: ");
String trash = ask.nextLine();
tasks.remove(trash);
System.out.println("Item deleted!");
break;
//Quit
case "q":
System.exit(0);
break;
}
}
ask.close();
}
}