-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
73 lines (61 loc) · 2.77 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(System.in);
System.out.print("Please input the file pathname: ");
String filepathname = in.nextLine();
Scanner inFile = new Scanner(new File(filepathname));
//The first command in the file must be to set the system date
//(eg. "startNewDay 03-Jan-2024"); and it cannot be undone
String cmdLine1 = inFile.nextLine();
String[] cmdLine1Parts = cmdLine1.split(" ");
System.out.println("\n> " + cmdLine1);
SystemDate.createTheInstance(cmdLine1Parts[1]);
while (inFile.hasNext()) {
String cmdLine = inFile.nextLine().trim();
//Blank lines exist in data file as separators. Skip them.
if (cmdLine.equals("")) continue;
System.out.println("\n> " + cmdLine);
//split the words in actionLine => create an array of word strings
String[] cmdParts = cmdLine.split(" ");
try {
if (cmdParts[0].equals("register")) {
new CmdRegister().execute(cmdParts);
} else if (cmdParts[0].equals("listMembers")){
new CmdListMembers().execute(cmdParts);
} else if (cmdParts[0].equals("startNewDay")){
new CmdStartNewDay().execute(cmdParts);
}else if (cmdParts[0].equals("create")){
new CmdCreateNewEquipment().execute(cmdParts);
}else if (cmdParts[0].equals("arrive")){
new CmdArriveEquipmentSet().execute(cmdParts);
}else if (cmdParts[0].equals("listEquipment")){
new CmdListEquipments().execute(cmdParts);
}else if (cmdParts[0].equals("listMemberStatus")){
new CmdListMemberStatus().execute(cmdParts);
}else if (cmdParts[0].equals("listEquipmentStatus")){
new CmdListEquipmentStatus().execute(cmdParts);
}else if (cmdParts[0].equals("undo")){
RecordedCommand.undoOneCommand();
}else if (cmdParts[0].equals("redo")){
RecordedCommand.redoOneCommand();
}else if (cmdParts[0].equals("borrow")){
new CmdBorrowEquipment().execute(cmdParts);
}else if (cmdParts[0].equals("request")){
new CmdRequestEquipment().execute(cmdParts);
}else{
throw new ExUnknownCmd();
}
} catch (ExUnknownCmd e){
System.out.println(e.getMessage());
break;
} catch ( Exception e) {
System.out.println(e.getMessage());
}
}
inFile.close();
in.close();
}
}