-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Kaitlyn] iP #461
base: master
Are you sure you want to change the base?
[Kaitlyn] iP #461
Changes from 16 commits
3b19ba1
456de8d
6e2b2a1
0d1b9a3
90ef94f
ae618f8
0fa0977
403e28c
1b2ebe2
46f1d9a
3f08797
299b09a
730d194
b533b2f
289082d
32469b6
24ca469
cb051f4
8be86c4
491a55a
ceb57be
398dd04
00e31b4
ef0e879
4a7970e
d6271e9
bae37bd
98f98c4
a599370
d03ab6c
ddf8545
46fa9d9
0cb4f87
7d6cd58
1bb0432
2bca07a
9829b69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
duke.task.Task list (Last updated Sep 1 2020, 04:37:04 AM): | ||
1. [T][✓] hello | ||
2. [D][✗] homework (by: Mar 3 2020) | ||
3. [E][✓] finish (at: Mar 4 2021, 12:00:00 PM) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package duke; | ||
|
||
import duke.command.Command; | ||
import duke.parser.Parser; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
public class Duke { | ||
|
||
private Storage storage; | ||
private TaskList tasks; | ||
private Ui ui; | ||
|
||
public Duke(String filePath) { | ||
this.ui = new Ui(); | ||
this.storage = new Storage(filePath); | ||
try { | ||
tasks = new TaskList(storage.load()); | ||
ui.showLoadedTasks(tasks); | ||
} catch (DukeException e) { | ||
ui.showLoadingError(e.getMessage()); | ||
tasks = new TaskList(); | ||
} | ||
} | ||
|
||
public void run() { | ||
ui.showWelcome(); | ||
boolean isExit = false; | ||
while (!isExit) { | ||
try { | ||
String fullCommand = ui.readCommand(); | ||
ui.showLine(); | ||
Command c = Parser.parse(fullCommand); | ||
c.execute(tasks, ui, storage); | ||
isExit = c.isExit(); | ||
} catch (DukeException e) { | ||
ui.showError(e.getMessage()); | ||
} finally { | ||
ui.showLine(); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
new Duke("data/tasks.txt").run(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package duke; | ||
|
||
public class DukeException extends Exception { | ||
public DukeException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package duke.command; | ||
|
||
import duke.*; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
public class ByeCommand extends Command { | ||
|
||
public ByeCommand() { | ||
super(); | ||
this.cmd = CMD.BYE; | ||
this.isExit = true; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { | ||
ui.display("OKAIS I IZ GOIN 2 NOM BYEEEEE C U !!!1!1!!"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return cmd.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package duke.command; | ||
|
||
public enum CMD { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think enum names should be written in PascalCase based on the coding standard? 🤔 |
||
BYE, | ||
LIST, | ||
TODO, | ||
DEADLINE, | ||
EVENT, | ||
DONE, | ||
DELETE, | ||
DEFAULT | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package duke.command; | ||
|
||
import duke.*; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
public class Command { | ||
protected CMD cmd; | ||
protected boolean isExit; | ||
|
||
public Command() { | ||
this.cmd = CMD.DEFAULT; | ||
this.isExit = false; | ||
} | ||
|
||
public boolean isExit() { | ||
return this.isExit; | ||
} | ||
|
||
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { | ||
ui.display("CAN I HAZ CHEEZBURGER?"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return cmd.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package duke.command; | ||
|
||
import duke.*; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
public class DeadlineCommand extends Command { | ||
private String taskName; | ||
private String by; | ||
|
||
public DeadlineCommand(String taskName, String by) { | ||
super(); | ||
this.cmd = CMD.DEADLINE; | ||
this.taskName = taskName; | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { | ||
ui.display("I PUT NEW TING IN DA LIST\n " + taskList.addDeadline(this.taskName, this.by) | ||
+ "\nNAO U HAS " + taskList.getNumberOfTasks() + " FINGS IN DA LIST LULZIES"); | ||
storage.save(taskList); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return cmd.toString() + ": " + taskName + "(" + by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package duke.command; | ||
|
||
import duke.*; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
public class DeleteCommand extends Command { | ||
private int idx; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps change this to |
||
public DeleteCommand(int idx) { | ||
super(); | ||
this.cmd = CMD.DONE; | ||
this.idx = idx; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { | ||
ui.display("TASK IZ NAO DELETZ!!!!1!11!\n" + " " | ||
+ taskList.popTask(this.idx) | ||
+ "\nNAO U HAS " + taskList.getNumberOfTasks() + " FINGS IN DA LIST LULZIES"); | ||
storage.save(taskList); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return cmd.toString() + ": " + idx; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package duke.command; | ||
|
||
import duke.*; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
public class DoneCommand extends Command { | ||
private int idx; | ||
public DoneCommand(int idx) { | ||
super(); | ||
this.cmd = CMD.DONE; | ||
this.idx = idx; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { | ||
taskList.markTaskAsDone(this.idx); | ||
storage.save(taskList); | ||
ui.display("TASK IZ NAO DUNZ!!!!1!11!\n" + " " + taskList.getTaskByIdx(this.idx)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return cmd.toString() + ": " + idx; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package duke.command; | ||
|
||
import duke.*; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
public class EventCommand extends Command { | ||
private String taskName; | ||
private String by; | ||
|
||
public EventCommand(String taskName, String by) { | ||
super(); | ||
this.cmd = CMD.EVENT; | ||
this.taskName = taskName; | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { | ||
ui.display("I PUT NEW TING IN DA LIST\n " + taskList.addEvent(this.taskName, this.by) | ||
+ "\nNAO U HAS " + taskList.getNumberOfTasks() + " FINGS IN DA LIST LULZIES"); | ||
storage.save(taskList); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return cmd.toString() + ": " + taskName + "(" + by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package duke.command; | ||
|
||
import duke.*; | ||
import duke.datetime.DateTimeUtility; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
public class ListCommand extends Command { | ||
private String by; | ||
|
||
public ListCommand() { | ||
super(); | ||
this.by = ""; | ||
this.cmd = CMD.LIST; | ||
} | ||
|
||
public ListCommand(String by) { | ||
this(); | ||
this.by = DateTimeUtility.formatString(by); | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think the nesting may be a bit deep here? I tend to find nested if-else hard to read when it goes down to 3-4 layers. One possible way of avoiding this:
|
||
if (taskList.isEmpty()) { | ||
ui.display("UR LIST HAZ NUTHIN LOLOL"); | ||
} else { | ||
if (this.by.isEmpty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the |
||
ui.display("U HAS DEES TINGS IN UR LIST.\n" + taskList.toString()); | ||
} else { | ||
try { | ||
String ret = TaskList.tasks2String(taskList.filterTasksByDate(this.by)); | ||
if (ret.isEmpty()) { | ||
ui.display("U HAZ NUTHIN DUE/HAPPENIN BY " | ||
+ DateTimeUtility.formatString(this.by) + "!! LULZIES"); | ||
} else { | ||
ui.display("U HAS DEES TINGS IN UR LIST DAT R DUE/HAPPENIN BY " | ||
+ DateTimeUtility.formatString(this.by) + ": \n" | ||
+ ret); | ||
} | ||
|
||
} catch (DukeException e) {} //exception will never be reached | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return cmd.toString() + (by.isEmpty() ? "" : " (" + by + ")"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package duke.command; | ||
|
||
import duke.*; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
public class TodoCommand extends Command { | ||
private String taskName; | ||
|
||
public TodoCommand(String taskName) { | ||
super(); | ||
this.cmd = CMD.TODO; | ||
this.taskName = taskName; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException { | ||
ui.display("I PUT NEW TING IN DA LIST\n " + taskList.addTodo(this.taskName) | ||
+ "\nNAO U HAS " + taskList.getNumberOfTasks() + " FINGS IN DA LIST LULZIES"); | ||
storage.save(taskList); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return cmd.toString() + ": " + taskName; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package duke.datetime; | ||
|
||
public enum DateTimeFormat { | ||
String, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the use of an enum to keep track of valid & invalid formats. Much better than using integer status codes. Perhaps these should be in uppercase as it is an enum? I noticed a few other variables in a similar position. |
||
Date, | ||
DateTime, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to avoid wildcard imports?