-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
76 lines (58 loc) · 2.83 KB
/
Main.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
import java.util.Scanner;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
class Main {
public static void main(String[] args) throws InterruptedException {
Scanner input = new Scanner(System.in);
ArrayList<String> items = new ArrayList<String>();
System.out.println("Commands:");
System.out.println("add - Adds an item to the database.");
System.out.println("remove - Removes an item from the database.");
System.out.println("change - Changes an item in the database.");
System.out.println("clear - Removes all items from the database.");
System.out.println("list - Lists all items in the database.");
System.out.println("quit - Stops the program.");
while (true) {
System.out.println("Enter a command:");
String inputResult = input.nextLine();
if (inputResult.equals("add")) { // add
System.out.println("Enter some text to add:");
String addInputResult = input.nextLine();
items.add(addInputResult);
System.out.println(addInputResult + " has been added to the database.");
TimeUnit.SECONDS.sleep(1);
} else if (inputResult.equals("remove")) { // remove
System.out.println("Enter an item you would like to remove:");
String removeInputResult = input.nextLine();
items.remove(removeInputResult);
System.out.println(removeInputResult + " has been removed from the database.");
TimeUnit.SECONDS.sleep(1);
} else if (inputResult.equals("change")) { // change
System.out.println("Enter an item you would like to change:");
String itemToChange = input.nextLine();
System.out.println("Enter its new name:");
String newItemName = input.nextLine();
int oldItemIndex = items.indexOf(itemToChange);
items.remove(itemToChange);
items.add(oldItemIndex, newItemName);
System.out.println(itemToChange + " has been changed to " + newItemName + ".");
TimeUnit.SECONDS.sleep(1);
} else if (inputResult.equals("clear")) { // clear
items.clear();
System.out.println("The database has been cleared.");
TimeUnit.SECONDS.sleep(1);
} else if (inputResult.equals("list")) { // list
System.out.println("The items in the list are: " + items + ".");
TimeUnit.SECONDS.sleep(1);
} else if (inputResult.equals("quit")) { // quit
System.out.println("Exiting the program...");
TimeUnit.SECONDS.sleep(1);
break;
} else { // not a command
System.out.println("That isn't a command.");
TimeUnit.SECONDS.sleep(1);
}
}
input.close();
}
}