-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mailbox.java
48 lines (40 loc) · 1.17 KB
/
Mailbox.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
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Scanner;
class Mailbox implements Serializable {
private ArrayList<String> messages;
Mailbox() {
this.messages = new ArrayList<>();
}
/**
* Clear mailbox
*/
private void clear() {
this.messages = new ArrayList<>();
System.out.println("All messages have been cleared.");
}
/**
* Receive a message from the notification system
* @param message is that message
*/
void enter(String message) {
this.messages.add(message);
}
/**
* Reads all messages and then asks user to if he/she wants them to be deleted
*/
void read() {
VerifyInput verify = new VerifyInput();
System.out.println("You have " + this.messages.size() + " messages.");
System.out.println();
for (String message : this.messages) {
System.out.println(message);
System.out.println();
}
System.out.println("Would you like to clear all messages? (1: Yes, 2: No)");
int input = verify.getValidChoice(2);
if (input == 1) {
this.clear();
}
}
}