-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveScreen.java
More file actions
48 lines (42 loc) · 1.2 KB
/
RemoveScreen.java
File metadata and controls
48 lines (42 loc) · 1.2 KB
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
public class RemoveScreen {
private static final String allKey = "A";
private static final String cancelKey = "C";
public static void startRemove(LinkedList<Day>.Node nodeToPull) {
// 1. Clear the screen
Printer.clearScreen();
// 2. Get the data we need
Day dayToPull = nodeToPull.getData();
Sleep[] sleepsList = dayToPull.getSleeps();
// 3. Display the message
Printer.displayRemove(sleepsList);
// 4. Get the user's selection
getUserSelection(nodeToPull, sleepsList);
}
private static void getUserSelection(LinkedList<Day>.Node nodeToPull,
Sleep[] sleepsList) {
Day dayToPull = nodeToPull.getData();
while(true) {
String userSelection = UserInput.getRegularInput();
if(userSelection.equals(allKey)) {
break;
}
if(userSelection.equals(cancelKey)) {
EntryScreen.startEntries(nodeToPull);
break;
}
try {
int intSelection = Integer.parseInt(userSelection);
dayToPull.removeSleep(sleepsList[intSelection]);
break;
} catch(NumberFormatException exc) {
Printer.displayNotAnInteger();
}
}
}
public static String getAllKey() {
return allKey;
}
public static String getCancelKey() {
return cancelKey;
}
}