Skip to content

Commit 3cb5ca5

Browse files
committed
A-Streams
1 parent 42a792a commit 3cb5ca5

21 files changed

Lines changed: 214 additions & 477 deletions
Lines changed: 51 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,61 @@
11
package prerthan.duke;
22

3-
import javafx.application.Platform;
4-
import prerthan.duke.exception.DukeEmptyDetailException;
5-
import prerthan.duke.task.TaskList;
6-
import prerthan.duke.command.Command;
7-
import prerthan.duke.exception.DukeInvalidArgumentException;
8-
import prerthan.duke.exception.DukeInvalidCommandException;
9-
import prerthan.duke.exception.DukeInvalidDateException;
103
import prerthan.duke.io.Input;
114
import prerthan.duke.io.Output;
125
import prerthan.duke.io.Storage;
13-
14-
import java.util.Optional;
6+
import prerthan.duke.task.TaskList;
157

168
/**
17-
*
9+
*
1810
*/
19-
public class Duke
20-
{
21-
public static TaskList tasks;
22-
public static Input input;
23-
public static Output output;
24-
public static Storage fileRW;
25-
26-
/**
27-
* Runs the main program loop.
28-
*
29-
* @return {@code false} when the user says 'bye'; otherwise, never returns.
30-
*/
31-
public static boolean programLoop()
32-
{
33-
boolean isExit = false;
34-
while (!isExit)
35-
{
36-
try
37-
{
38-
Optional<Command> possibleCommand = input.nextLine().getCommand();
39-
if (!possibleCommand.isPresent())
40-
{
41-
output.say("Input cannot be empty; please enter a command.");
42-
continue;
43-
}
44-
possibleCommand.get().execute(tasks, fileRW, output);
45-
isExit = possibleCommand.get().willTerminate();
46-
}
47-
catch (DukeInvalidArgumentException | DukeInvalidCommandException | DukeEmptyDetailException
48-
| DukeInvalidDateException e)
49-
{
50-
output.sayError(e);
51-
}
52-
}
53-
return isExit;
54-
}
55-
56-
/**
57-
* Cleans up objects and quits the program by calling {@link System#exit(int)}.
58-
*/
59-
public static void exit()
60-
{
61-
output.sayGoodBye();
62-
63-
input.close();
64-
output.close();
65-
Platform.exit();
66-
System.exit(0);
67-
}
68-
69-
public static void main(String[] args)
70-
{
71-
// Initialises file and UI I/O
72-
fileRW = new Storage("data", "duke.txt");
73-
input = new Input();
74-
output = new Output();
75-
76-
// Greets the user.
77-
output.sayHello();
78-
79-
// Creates the task list
80-
tasks = fileRW.loadFromFile();
81-
82-
if (programLoop())
83-
{
84-
exit();
85-
}
86-
}
11+
public class Duke {
12+
public static TaskList tasks;
13+
public static Input input;
14+
public static Output output;
15+
public static Storage fileRW;
16+
17+
public boolean run() {
18+
return false;
19+
}
20+
21+
/**
22+
* Runs the main program loop.
23+
*
24+
* @return {@code false} when the user says 'bye'; otherwise, never returns.
25+
*/
26+
public static boolean programLoop() {
27+
boolean exitLoop = false;
28+
String command;
29+
30+
input.nextLine();
31+
return false;
32+
}
33+
34+
/**
35+
* Cleans up objects and quits the program by calling {@link System#exit(int)}.
36+
*/
37+
public static void exit() {
38+
output.sayGoodBye();
39+
40+
input.close();
41+
output.close();
42+
43+
System.exit(0);
44+
}
45+
46+
public static void main(String[] args) {
47+
// Initialises file and UI I/O
48+
fileRW = new Storage("data", "duke.txt");
49+
input = new Input();
50+
output = new Output();
51+
52+
// Greets the user.
53+
output.sayHello();
54+
55+
// Creates the task list
56+
tasks = new TaskList();
8757

88-
public String getResponse(String input)
89-
{
90-
return "";
91-
}
58+
if (programLoop())
59+
exit();
60+
}
9261
}

src/main/java/prerthan/duke/DukeLauncher.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/java/prerthan/duke/Main.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/prerthan/duke/command/AddCommand.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import prerthan.duke.exception.DukeEmptyDetailException;
44
import prerthan.duke.task.TaskList;
5+
import prerthan.duke.task.Todo;
56
import prerthan.duke.exception.DukeInvalidDateException;
6-
import prerthan.duke.io.Output;
77
import prerthan.duke.io.Storage;
88
import prerthan.duke.task.Deadline;
99
import prerthan.duke.task.Event;
10-
import prerthan.duke.task.Todo;
1110

1211
/**
1312
* AddCommand
@@ -20,35 +19,29 @@ public AddCommand(String detail, CommandName commandName) {
2019
this.commandName = commandName;
2120
}
2221

23-
public AddCommand(String detail, String timeString, CommandName commandName)
24-
{
22+
public AddCommand(String detail, String timeString, CommandName commandName) {
2523
super(detail, timeString);
2624
this.commandName = commandName;
2725
}
2826

29-
public AddCommand(String detail, String startString, String endString, CommandName commandName)
30-
{
27+
public AddCommand(String detail, String startString, String endString, CommandName commandName) {
3128
super(detail, startString, endString);
32-
this.commandName = commandName;
3329
}
3430

35-
@Override public void execute(TaskList tasks, Storage storage, Output output)
36-
throws DukeEmptyDetailException, DukeInvalidDateException
37-
{
38-
switch (this.commandName)
39-
{
40-
case TODO:
41-
tasks.addTask(new Todo(this.argumentTokens[0]));
42-
break;
43-
case EVENT:
44-
tasks.addTask(new Event(this.argumentTokens[0], this.argumentTokens[1],
45-
this.argumentTokens[2]));
46-
break;
47-
case DEADLINE:
48-
tasks.addTask(new Deadline(this.argumentTokens[0], this.argumentTokens[1]));
49-
break;
50-
default:
51-
break;
31+
@Override
32+
public void execute(final TaskList tasks, final Storage storage)
33+
throws DukeEmptyDetailException, DukeInvalidDateException {
34+
switch (this.commandName) {
35+
case TODO:
36+
tasks.addTask(new Todo(this.argumentTokens[0]));
37+
case EVENT:
38+
tasks.addTask(new Event(this.argumentTokens[0], this.argumentTokens[1], this.argumentTokens[2]));
39+
break;
40+
case DEADLINE:
41+
tasks.addTask(new Deadline(this.argumentTokens[0], this.argumentTokens[1]));
42+
break;
43+
default:
44+
break;
5245
}
5346
}
5447
}
Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
11
package prerthan.duke.command;
22

3+
import prerthan.duke.exception.DukeEmptyDetailException;
34
import prerthan.duke.task.TaskList;
4-
import prerthan.duke.Duke;
55
import prerthan.duke.exception.DukeInvalidArgumentException;
6-
import prerthan.duke.io.Output;
6+
import prerthan.duke.exception.DukeInvalidDateException;
77
import prerthan.duke.io.Storage;
88

99
/**
1010
* ByeCommand
1111
*/
12-
public class ByeCommand extends Command
13-
{
14-
private final CommandName commandName = CommandName.BYE;
12+
public class ByeCommand extends Command {
1513

16-
public ByeCommand(String[] argumentTokens) throws DukeInvalidArgumentException
17-
{
18-
if (argumentTokens.length != 0)
19-
{
20-
throw new DukeInvalidArgumentException("Bye command should have no arguments.",
21-
argumentTokens, this.commandName, this.getClass().getSimpleName());
22-
}
23-
}
14+
public ByeCommand(String[] argumentTokens) throws DukeInvalidArgumentException {
15+
super(argumentTokens);
16+
this.commandName = CommandName.BYE;
2417

25-
@Override public void execute(TaskList tasks, Storage storage, Output output)
26-
{
27-
Duke.exit();
28-
}
29-
30-
@Override
31-
public boolean willTerminate()
32-
{
33-
return true;
34-
}
18+
if (argumentTokens.length() >= 1) {
19+
throw new DukeInvalidArgumentException("Bye command must have no arguments.",
20+
ByeCommand.class.getSimpleName());
21+
}
22+
}
23+
24+
@Override
25+
public void execute(TaskList tasks, Storage storage) throws DukeEmptyDetailException, DukeInvalidDateException {
26+
27+
}
3528
}

0 commit comments

Comments
 (0)