Skip to content
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

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
5e92ee7
Level-1
CheongYeeMing Aug 19, 2021
6969459
Level-2
CheongYeeMing Aug 19, 2021
8972ebe
Level-3
CheongYeeMing Aug 19, 2021
1436982
Level-4
CheongYeeMing Aug 19, 2021
4bac102
A-TextUiTesting
CheongYeeMing Aug 19, 2021
c104015
Level-5
CheongYeeMing Aug 19, 2021
87e0083
Level-6
CheongYeeMing Aug 19, 2021
7ba16ae
Level-7
CheongYeeMing Aug 27, 2021
424d729
Level-8
CheongYeeMing Aug 27, 2021
8979148
Level-8
CheongYeeMing Aug 27, 2021
69ad545
A-MoreOOP
CheongYeeMing Aug 30, 2021
ddb01e3
A-Packages
CheongYeeMing Aug 30, 2021
15ee3f3
A-JUnit
CheongYeeMing Aug 30, 2021
19b9b20
A-JavaDoc
CheongYeeMing Aug 30, 2021
c85d8a3
branch-A-CodingStandard
CheongYeeMing Aug 30, 2021
40778c3
Level-9
CheongYeeMing Aug 30, 2021
b1349d6
Merge remote-tracking branch 'origin/add-gradle-support'
CheongYeeMing Sep 6, 2021
d2c09d3
A-Gradle
CheongYeeMing Sep 7, 2021
fdfd51d
A-CheckStyle
CheongYeeMing Sep 7, 2021
d1862f5
Level-10
CheongYeeMing Sep 9, 2021
3e88ffe
A-Assertions
CheongYeeMing Sep 11, 2021
b5e4370
A-CodeQuality
CheongYeeMing Sep 11, 2021
cc2c726
A-Streams
CheongYeeMing Sep 11, 2021
78718b2
Merge pull request #1 from CheongYeeMing/branch-A-Assertions
CheongYeeMing Sep 11, 2021
6afe26b
Merge pull request #2 from CheongYeeMing/branch-A-CodeQuality
CheongYeeMing Sep 11, 2021
9038a5e
Merge pull request #3 from CheongYeeMing/branch-A-Streams
CheongYeeMing Sep 11, 2021
484517f
Merge branch 'branch-A-CodeQuality' of https://github.com/CheongYeeMi…
CheongYeeMing Sep 11, 2021
838ce6b
Merge branch 'branch-A-Streams' of https://github.com/CheongYeeMing/ip
CheongYeeMing Sep 11, 2021
9ea146b
Merge branch 'master' of https://github.com/CheongYeeMing/ip
CheongYeeMing Sep 11, 2021
3e0f472
BCD-Extension
CheongYeeMing Sep 11, 2021
d7a6671
A-BetterGui
CheongYeeMing Sep 11, 2021
e844522
A-UserGuide
CheongYeeMing Sep 13, 2021
72e043b
A-Release
CheongYeeMing Sep 13, 2021
6f6745e
Merge branch 'master' of https://github.com/CheongYeeMing/ip
CheongYeeMing Sep 13, 2021
3c14a89
A-UserGuide
CheongYeeMing Sep 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.idea/
/out/
/*.iml
*.class

# Gradle build files
/.gradle/
Expand Down
4 changes: 4 additions & 0 deletions data/duke.txt
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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: duke.Duke

70 changes: 70 additions & 0 deletions src/main/java/duke/Duke.java
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();
}
}
41 changes: 41 additions & 0 deletions src/main/java/duke/command/AddCommand.java
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.

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

*
* @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.

Choose a reason for hiding this comment

The 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());
}
}
38 changes: 38 additions & 0 deletions src/main/java/duke/command/Command.java
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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mention a DukeCommand in the JavaDocs, but the constructor creates a Command, so it might be good to streamline this and standardize to 1 name for the Command class

*
* @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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can consider renaming the method execute or simply run to clearly distinguish the method to run the command from the type of command (i.e. AddCommand, DeleteCommand etc.)

}
43 changes: 43 additions & 0 deletions src/main/java/duke/command/DeleteCommand.java
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());
}
}

40 changes: 40 additions & 0 deletions src/main/java/duke/command/DoneCommand.java
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());
}
}
35 changes: 35 additions & 0 deletions src/main/java/duke/command/ExitCommand.java
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());
}
}
37 changes: 37 additions & 0 deletions src/main/java/duke/command/FindCommand.java
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));
}
}
34 changes: 34 additions & 0 deletions src/main/java/duke/command/ListCommand.java
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);
}
}
Loading