-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
39 lines (35 loc) · 1.62 KB
/
Main.java
File metadata and controls
39 lines (35 loc) · 1.62 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
import java.util.Scanner;
public class Main {
private static String addCommand = "add Василий Петров " +
"vasily.petrov@gmail.com +79215637722";
private static String commandExamples = "\t" + addCommand + "\n" +
"\tlist\n\tcount\n\tremove Василий Петров";
private static String commandError = "Wrong command! Available command examples: \n" +
commandExamples;
private static String helpText = "Command examples:\n" + commandExamples;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
CustomerStorage executor = new CustomerStorage();
for (; ; ) {
try {
String command = scanner.nextLine();
String[] tokens = command.split("\\s+", 2);
if (tokens[0].equals("add") & tokens.length > 1) {
executor.addCustomer(tokens[1]);
} else if (tokens[0].equals("list")) {
executor.listCustomers();
} else if (tokens[0].equals("remove") & tokens.length > 1) {
executor.removeCustomer(tokens[1]);
} else if (tokens[0].equals("count")) {
System.out.println("There are " + executor.getCount() + " customers");
} else if (tokens[0].equals("help")) {
System.out.println(helpText);
} else {
System.out.println((commandError));
}
} catch (RuntimeException ex) {
System.out.println(ex.getMessage());
}
}
}
}