-
Notifications
You must be signed in to change notification settings - Fork 454
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
[Cheong Yee Ming] iP #462
base: master
Are you sure you want to change the base?
[Cheong Yee Ming] iP #462
Changes from 16 commits
d839859
5e92ee7
6969459
8972ebe
1436982
4bac102
c104015
87e0083
7ba16ae
424d729
8979148
69ad545
ddb01e3
15ee3f3
19b9b20
c85d8a3
40778c3
b1349d6
d2c09d3
fdfd51d
d1862f5
3e88ffe
b5e4370
cc2c726
78718b2
6afe26b
9038a5e
484517f
838ce6b
9ea146b
3e0f472
d7a6671
e844522
72e043b
6f6745e
3c14a89
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/.idea/ | ||
/out/ | ||
/*.iml | ||
*.class | ||
|
||
# Gradle build files | ||
/.gradle/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
T | 1 | run | ||
D | 0 | work | 1999-02-02T01:01 | ||
E | 1 | project meeting | 2021-08-31T15:00 | ||
T | 0 | sleep |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: duke.Duke | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package duke; | ||
|
||
import duke.command.Command; | ||
import duke.command.ExitCommand; | ||
import duke.exception.DukeException; | ||
import duke.parser.Parser; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
import java.util.Scanner; | ||
|
||
/** | ||
* Program to keep track of a list of tasks. | ||
* | ||
* @author Cheong Yee Ming | ||
* @version Duke Level-9 | ||
*/ | ||
public class Duke { | ||
|
||
// List to store all user inputs | ||
private final TaskList taskList; | ||
private final Storage storage; | ||
private final Ui ui; | ||
private final Parser parser; | ||
|
||
/** | ||
* Constructor for Duke. | ||
*/ | ||
public Duke() { | ||
taskList = new TaskList(); | ||
storage = new Storage(); | ||
ui = new Ui(); | ||
parser = new Parser(taskList, storage, ui); | ||
} | ||
|
||
/** | ||
* Runs when bot is first initialised. | ||
* Greets the user and loads data from local directory if present | ||
* If not, local directory and local data file are created. | ||
* Takes in user input and responds respectively. | ||
*/ | ||
private void initiateSystem() { | ||
taskList.loadFromStorage(storage.load()); | ||
ui.greet(); | ||
Scanner sc = new Scanner(System.in); | ||
boolean isActive = true; | ||
|
||
while (isActive) { | ||
String userInput = sc.nextLine(); | ||
try { | ||
Command command = parser.parseUserInput(userInput); | ||
command.runCommand(); | ||
isActive = !(command instanceof ExitCommand); | ||
} catch (DukeException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
} | ||
sc.close(); | ||
} | ||
|
||
/** | ||
* Main function for Duke program. | ||
* @param args Null. | ||
*/ | ||
public static void main(String[] args) { | ||
Duke duke = new Duke(); | ||
duke.initiateSystem(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package duke.command; | ||
|
||
import duke.storage.Storage; | ||
import duke.task.Task; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
/** | ||
* Command to add a task to the task list. | ||
* | ||
* @author Cheong Yee Ming | ||
* @version Duke Level-9 | ||
*/ | ||
public class AddCommand extends Command { | ||
private final Task task; | ||
|
||
/** | ||
* Constructor for an AddCommand. | ||
* | ||
* @param taskList Handles all operations regarding tasks. | ||
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 how the descriptions have the same indentation which makes it easy to read. 👍 |
||
* @param storage Save and load data from local directory. | ||
* @param ui Prints message with respect to user input. | ||
* @param task Task to be added to task list. | ||
*/ | ||
public AddCommand(TaskList taskList, Storage storage, Ui ui, Task task) { | ||
super(taskList, storage, ui); | ||
this.task = task; | ||
} | ||
|
||
/** | ||
* Executes runCommand. Adds the task to the task list, | ||
* prints a message to tell user that task has been added | ||
* and update local data file. | ||
*/ | ||
@Override | ||
public void runCommand() { | ||
taskList.addTask(task); | ||
ui.taskAddedMessage(task, taskList.size()); | ||
storage.save(taskList.getList()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package duke.command; | ||
|
||
import duke.exception.DukeException; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
/** | ||
* Commands that can be executed by Duke. | ||
* | ||
* @author Cheong Yee Ming | ||
* @version Duke Level-9 | ||
*/ | ||
public abstract class Command { | ||
protected final TaskList taskList; | ||
protected final Storage storage; | ||
protected final Ui ui; | ||
|
||
/** | ||
* Constructor for a DukeCommand. | ||
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. You mention a |
||
* | ||
* @param taskList Handles all operations regarding tasks. | ||
* @param storage Save and load data from local directory. | ||
* @param ui Prints message with respect to user input. | ||
*/ | ||
public Command(TaskList taskList, Storage storage, Ui ui) { | ||
this.taskList = taskList; | ||
this.storage = storage; | ||
this.ui = ui; | ||
} | ||
|
||
/** | ||
* Executes the command. | ||
* | ||
* @throws DukeException when an error occurs. | ||
*/ | ||
public abstract void runCommand() 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. Maybe you can consider renaming the method |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package duke.command; | ||
|
||
import duke.exception.NoSuchTaskException; | ||
import duke.storage.Storage; | ||
import duke.task.Task; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
/** | ||
* Command to remove a task from the task list. | ||
* | ||
* @author Cheong Yee Ming | ||
* @version Duke Level-9 | ||
*/ | ||
public class DeleteCommand extends Command { | ||
private final int taskNumber; | ||
|
||
/** | ||
* Constructor for an AddCommand. | ||
* | ||
* @param taskList Handles all operations regarding tasks. | ||
* @param storage Save and load data from local directory. | ||
* @param ui Prints message with respect to user input. | ||
* @param taskNumber Task number of task to be removed from task list. | ||
*/ | ||
public DeleteCommand(TaskList taskList, Storage storage, Ui ui, int taskNumber) { | ||
super(taskList, storage, ui); | ||
this.taskNumber = taskNumber; | ||
} | ||
|
||
/** | ||
* Executes runCommand. Removes the task from the task list, | ||
* prints a message to tell user that task has been removed | ||
* and update local data file. | ||
*/ | ||
@Override | ||
public void runCommand() throws NoSuchTaskException { | ||
Task deletedTask = taskList.deleteTask(taskNumber); | ||
ui.taskDeletedMessage(deletedTask, taskList.size()); | ||
storage.save(taskList.getList()); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package duke.command; | ||
|
||
import duke.exception.NoSuchTaskException; | ||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
/** | ||
* Command to mark a task in the task list as done. | ||
* | ||
* @author Cheong Yee Ming | ||
* @version Duke Level-9 | ||
*/ | ||
public class DoneCommand extends Command { | ||
private final int taskNumber; | ||
|
||
/** | ||
* Constructor for an AddCommand. | ||
* | ||
* @param taskList Handles all operations regarding tasks. | ||
* @param storage Save and load data from local directory. | ||
* @param ui Prints message with respect to user input. | ||
* @param taskNumber Task number of task to be marked as done. | ||
*/ | ||
public DoneCommand(TaskList taskList, Storage storage, Ui ui, int taskNumber) { | ||
super(taskList, storage, ui); | ||
this.taskNumber = taskNumber; | ||
} | ||
|
||
/** | ||
* Executes runCommand. Marks the task as done, | ||
* prints a message to tell user that task has been marked as done | ||
* and update local data file. | ||
*/ | ||
@Override | ||
public void runCommand() throws NoSuchTaskException { | ||
ui.taskDoneMessage(taskList.markAsDone(taskNumber)); | ||
storage.save(taskList.getList()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package duke.command; | ||
|
||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
/** | ||
* Command to exit the Duke program. | ||
* | ||
* @author Cheong Yee Ming | ||
* @version Duke Level-9 | ||
*/ | ||
public class ExitCommand extends Command { | ||
/** | ||
* Constructor for a DukeCommand. | ||
* | ||
* @param taskList Handles all operations regarding tasks. | ||
* @param storage Save and load data from local directory. | ||
* @param ui Prints message with respect to user input. | ||
*/ | ||
public ExitCommand(TaskList taskList, Storage storage, Ui ui) { | ||
super(taskList, storage, ui); | ||
} | ||
|
||
/** | ||
* Executes runCommand. | ||
* Prints a message to say good bye to user | ||
* and update local data file. | ||
*/ | ||
@Override | ||
public void runCommand() { | ||
ui.bye(); | ||
storage.save(taskList.getList()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package duke.command; | ||
|
||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
/** | ||
* Command to search for tasks containing the keyword. | ||
* | ||
* @author Cheong Yee Ming | ||
* @version Duke Level-9 | ||
*/ | ||
public class FindCommand extends Command { | ||
private final String keyword; | ||
|
||
/** | ||
* Constructor for FindCommand. | ||
* | ||
* @param taskList Handles all operations regarding tasks. | ||
* @param storage Save and load data from local directory. | ||
* @param ui Prints message with respect to user input. | ||
* @param keyword Keyword to find related tasks. | ||
*/ | ||
public FindCommand(TaskList taskList, Storage storage, Ui ui, String keyword) { | ||
super(taskList, storage, ui); | ||
this.keyword = keyword; | ||
} | ||
|
||
/** | ||
* Executes command to print out | ||
* every task containing the keyword. | ||
*/ | ||
@Override | ||
public void runCommand() { | ||
ui.printFindTask(taskList.findRelatedTask(keyword)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package duke.command; | ||
|
||
import duke.storage.Storage; | ||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
/** | ||
* Command to list all tasks in the task list. | ||
* | ||
* @author Cheong Yee Ming | ||
* @version Duke Level-9 | ||
*/ | ||
public class ListCommand extends Command { | ||
/** | ||
* Constructor for a DukeCommand. | ||
* | ||
* @param taskList Handles all operations regarding tasks. | ||
* @param storage Save and load data from local directory. | ||
* @param ui Prints message with respect to user input. | ||
*/ | ||
public ListCommand(TaskList taskList, Storage storage, Ui ui) { | ||
super(taskList, storage, ui); | ||
} | ||
|
||
/** | ||
* Executes runCommand. | ||
* Prints the list of tasks in the task list | ||
* in order of addition to task list. | ||
*/ | ||
@Override | ||
public void runCommand() { | ||
ui.listTaskMessage(taskList); | ||
} | ||
} |
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.
I think it would be good to document down what is contained in each Command