Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
55cebd9
Add skeletal version of Duke
ZhuLeYao Feb 5, 2023
2a7c671
Add list to store text entered by user
ZhuLeYao Feb 6, 2023
03fbf9b
Revert "Add list to store text entered by user"
ZhuLeYao Feb 6, 2023
09fcc0c
Add list to store text entered by user
ZhuLeYao Feb 6, 2023
b5d3ce2
Add option to mark tasks and Task class
ZhuLeYao Feb 7, 2023
0035506
Add task types: Todo, Deadline and Event
ZhuLeYao Feb 7, 2023
b5e1e00
Add exceptions to task commands
ZhuLeYao Feb 7, 2023
2008de1
Add function to delete a task
ZhuLeYao Feb 7, 2023
70feaa9
Fix time to be read as date time instead of string
ZhuLeYao Feb 9, 2023
441456a
Add save task list to hard disk function
ZhuLeYao Feb 9, 2023
98df06b
Merge branch 'branch-level-7'
ZhuLeYao Feb 12, 2023
e5a768c
Remove print lines for debugging
ZhuLeYao Feb 12, 2023
909e8e0
Update git ignore list
ZhuLeYao Feb 12, 2023
6025774
Merge branch 'branch-level-8'
ZhuLeYao Feb 12, 2023
bdac24c
Edit data time format of task saved to hard disk
ZhuLeYao Feb 12, 2023
3172b9d
Add command to find deadlines or events on date
ZhuLeYao Feb 12, 2023
81d434a
Move exception methods from Duke to DukeException
ZhuLeYao Feb 12, 2023
d91abba
Refactor the code to extract out closely related code as classes
ZhuLeYao Feb 16, 2023
35b7277
Divide classes into packages
ZhuLeYao Feb 17, 2023
a21fea9
Merge branch 'add-gradle-support'
ZhuLeYao Feb 17, 2023
81658cd
Add JUnit tests for Todo and TaskList
ZhuLeYao Feb 20, 2023
cc98e9e
Package the App as a JAR file
ZhuLeYao Feb 20, 2023
2ad5871
Add JavaDoc comments
ZhuLeYao Feb 20, 2023
3c4cd7d
Tweak the code to comply with a coding standard
ZhuLeYao Feb 20, 2023
a081d94
Add function for users to find a task by searching for a keyword
ZhuLeYao Feb 20, 2023
c5a2e16
Merge branch 'branch-A-JavaDoc'
ZhuLeYao Feb 20, 2023
bb5df21
Merge branch 'branch-A-CodingStandard'
ZhuLeYao Feb 20, 2023
8f8d7d2
Merge branch 'branch-Level-9'
ZhuLeYao Feb 20, 2023
94259dd
Update JavaDoc comments for duke.main package
ZhuLeYao Feb 20, 2023
5e7d440
Update JavaDoc comments for duke.task package
ZhuLeYao Feb 20, 2023
2047ab4
Update JavaDoc comments for duke.exception package
ZhuLeYao Feb 20, 2023
f6091ea
Create GUi for Duke
ZhuLeYao Feb 22, 2023
74ae1f0
Remove border lines from Ui
ZhuLeYao Feb 22, 2023
50b766b
Edit ShadowJar values
ZhuLeYao Feb 22, 2023
34c226e
Merge branch 'branch-Level-10'
ZhuLeYao Feb 22, 2023
a962e4b
Add Assertions for assumptions in main
ZhuLeYao Feb 23, 2023
7af212d
Modify git.ignore to allow ACTUAL.TXT
ZhuLeYao Feb 23, 2023
eadcc8a
Improve code quality
ZhuLeYao Feb 23, 2023
b766be6
Merge pull request #2 from ZhuLeYao/branch-A-Assertions
ZhuLeYao Feb 23, 2023
a86c23a
Merge branch 'master' of github.com:ZhuLeYao/ip
ZhuLeYao Feb 23, 2023
97912f0
Merge pull request #3 from ZhuLeYao/branch-A-CodeQuality
ZhuLeYao Feb 23, 2023
b2cfd05
Merge branch 'master' of github.com:ZhuLeYao/ip
ZhuLeYao Feb 23, 2023
99bac14
Add a way to archive items
ZhuLeYao Feb 23, 2023
b39df94
Merge branch 'branch-BCD-Extension'
ZhuLeYao Feb 23, 2023
daeeed6
Add Ui image and update README.md
ZhuLeYao Feb 23, 2023
cbb483e
Add images into README.md
ZhuLeYao Feb 23, 2023
fcc5170
Format README.md
ZhuLeYao Feb 23, 2023
2a9e367
Format README.md
ZhuLeYao Feb 23, 2023
387cb45
Edit boolean naming of isMarked
ZhuLeYao Feb 23, 2023
cad8d37
Correct archive saving mechanism
ZhuLeYao Feb 23, 2023
e9e2226
Abstract long methods
ZhuLeYao Mar 20, 2023
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
58 changes: 58 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
public class Deadline extends Task {

Choose a reason for hiding this comment

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

Needs Javadocs for these public classes & public methods

private final String taskType;
private final String taskDeadline;

Deadline(int taskNumber, boolean taskStatus, String task, String taskDeadline, int totalNumOfTasks) {
super(taskNumber, taskStatus, task, totalNumOfTasks);
this.taskType = "[D]";
this.taskDeadline = taskDeadline;
}

@Override
public void markAsDone() {

Choose a reason for hiding this comment

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

Good splitting of lines!

System.out.println("\t____________________________________________________________" +
"\n\t Nice! I've marked this task as done:\n" +
"\t " + this.taskType + "[X]" + " " + super.task +
" (by: " + this.taskDeadline + ")" +
"\n\t____________________________________________________________");
}

@Override
public void unmarkAsUndone() {
System.out.println("\t____________________________________________________________" +
"\n\t OK, I've marked this task as not done yet:\n" +
"\t " + this.taskType + "[ ]" + " " + super.task +
" (by: " + this.taskDeadline + ")" +
"\n\t____________________________________________________________");
}

public void printDeadlineTask() {
System.out.println("\t____________________________________________________________" +
"\n\t Got it. I've added this task:" +
"\n\t [D]" + super.getTaskStatus() + " " + super.task +
"(by: " + this.taskDeadline + ")" +
"\n\t Now you have " + super.totalNumOfTasks + " tasks in the list." +
"\n\t____________________________________________________________");
}

@Override
public void printDelete() {
int newTotalNumOfTasks = super.totalNumOfTasks - 1;
System.out.println("\t____________________________________________________________" +
"\n\t Noted. I've removed this task:" +
"\n\t " + this.taskType +
super.getTaskStatus() + " " + super.task + " (by: " + this.taskDeadline + ")" +
"\n\t Now you have " + newTotalNumOfTasks + " tasks in the list." +
"\n\t____________________________________________________________");
}

@Override
public String getTaskType() {
return this.taskType;
}

@Override
public String getDeadline() {
return this.taskDeadline;
}
}
244 changes: 244 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,254 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class Duke {

Scanner sc = new Scanner(System.in);

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

Duke duke = new Duke();
duke.chatDuke();
}

public void chatDuke() {

List<Task> allTasks = new ArrayList<>();

this.printGreetingMessage();

boolean saidBye = false;
while (!saidBye) {
String command = sc.nextLine();

try {
if (command.equals("list")) {
this.printCommandList(allTasks);

Choose a reason for hiding this comment

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

unnecessary qualifier to this

} else if (command.startsWith("mark")) {
missingIndexException(command);
invalidIndexException(command, allTasks.size());
String[] str = command.split(" ");
int taskIndex = Integer.parseInt(str[1]) - 1;
Task oldTask = allTasks.get(taskIndex);
if (oldTask.getTaskType().equals("[T]")) {
Todo todo = new Todo(oldTask.getTaskNumber(),
true, oldTask.getTask(),
allTasks.size());
allTasks.set(taskIndex, todo);
todo.markAsDone();
} else if (oldTask.getTaskType().equals("[D]")) {
Deadline deadline = new Deadline(oldTask.getTaskNumber(),
true, oldTask.getTask(),
oldTask.getDeadline(), allTasks.size());
allTasks.set(taskIndex, deadline);
deadline.markAsDone();
} else if (oldTask.getTaskType().equals("[E]")) {
Event event = new Event(oldTask.getTaskNumber(),
true, oldTask.getTask(),
oldTask.getEventStartTime(),
oldTask.getEventEndTime(), allTasks.size());
allTasks.set(taskIndex, event);
event.markAsDone();
}
} else if (command.startsWith("unmark")) {
missingIndexException(command);
invalidIndexException(command, allTasks.size());
String[] str = command.split(" ");
int taskIndex = Integer.parseInt(str[1]) - 1;
Task oldTask = allTasks.get(taskIndex);
if (oldTask.getTaskType().equals("[T]")) {
Todo todo = new Todo(oldTask.getTaskNumber(),
false, oldTask.getTask(),
allTasks.size());
allTasks.set(taskIndex, todo);
todo.unmarkAsUndone();
} else if (oldTask.getTaskType().equals("[D]")) {
Deadline deadline = new Deadline(oldTask.getTaskNumber(),
false, oldTask.getTask(),
oldTask.getDeadline(), allTasks.size());
allTasks.set(taskIndex, deadline);
deadline.unmarkAsUndone();
} else if (oldTask.getTaskType().equals("[E]")) {
Event event = new Event(oldTask.getTaskNumber(),
false, oldTask.getTask(),
oldTask.getEventStartTime(),
oldTask.getEventEndTime(), allTasks.size());
allTasks.set(taskIndex, event);
event.unmarkAsUndone();
}
} else if (command.startsWith("todo")) {
emptyCommandException(command);
String[] str = command.split("todo");
String taskName = str[1];
Todo todo = new Todo(allTasks.size(), false,
taskName, allTasks.size() + 1);
allTasks.add(todo);
todo.printToDoTask();
} else if (command.startsWith("deadline")) {
emptyCommandException(command);
missingTimingException(command);
String[] str = command.split("/by");
String taskName = str[0].split("deadline")[1];
String taskDeadline = str[1];
Deadline deadline = new Deadline(allTasks.size(), false,
taskName, taskDeadline, allTasks.size() + 1);
allTasks.add(deadline);
deadline.printDeadlineTask();
} else if (command.startsWith("event")) {
emptyCommandException(command);
missingTimingException(command);
String[] str = command.split("/from");
String taskName = str[0].split("event")[1];
String[] eventStartEndTime = str[1].split("/to");
String eventStartTime = eventStartEndTime[0];
String eventEndTime = eventStartEndTime[1];
Event event = new Event(allTasks.size(), false,
taskName, eventStartTime, eventEndTime, allTasks.size() + 1);
allTasks.add(event);
event.printEventTask();
} else if (command.startsWith("delete")) {
missingIndexException(command);
invalidIndexException(command, allTasks.size());
String[] str = command.split(" ");
int taskIndex = Integer.parseInt(str[1]) - 1;
Task task = allTasks.get(taskIndex);
task.printDelete();
allTasks.remove(taskIndex);
} else if (command.equals("bye")){
saidBye = true;
this.printByeMessage();
} else {
invalidCommandException(command);
}
} catch (DukeException d) {
System.out.println(d.getMessage());
} catch (NumberFormatException nfe) {
System.out.println("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be a non-integer." +
"\n\t____________________________________________________________");
}
}
}

public void printGreetingMessage() {
System.out.println("\t____________________________________________________________" +
"\n\t Hello! I'm Duke\n" +
"\t What can I do for you?" +
"\n\t____________________________________________________________");
}

public void printCommandList(List<Task> allTasks) {
System.out.println("\t____________________________________________________________");
System.out.println("\t Here are the tasks in your list:");
for (int i = 0; i < allTasks.size(); i++) {
int numbering = i + 1;
Task task = allTasks.get(i);
String time = "";
if (task.getTaskType().equals("[D]")) {
time = " (by: " + task.getDeadline() + ")";
} else if (task.getTaskType().equals("[E]")) {
time = " (from: " + task.getEventStartTime() + " to: "
+ task.getEventEndTime() + ")";
}
System.out.println("\t " + numbering + "." +
task.getTaskType() + task.getTaskStatus() + " "
+ task.getTask() + time);
}

System.out.println("\t____________________________________________________________");
}

public void printByeMessage() {
System.out.println("\t____________________________________________________________" +
"\n\t Bye. Hope to see you again soon!" +
"\n\t____________________________________________________________");
}

public void emptyCommandException(String command) throws DukeException {
switch (command) {
case "todo":
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The description of a todo cannot be empty." +
"\n\t____________________________________________________________");
case "deadline":
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The description of a deadline cannot be empty." +
"\n\t____________________________________________________________");
case "event":
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The description of an event cannot be empty." +
"\n\t____________________________________________________________");
}
}

public void missingTimingException(String command) throws DukeException {
if (command.startsWith("deadline") && !command.contains("/by")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The timing of a deadline cannot be empty." +
"\n\t____________________________________________________________");
} else if (command.startsWith("event") && !command.contains("/from")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The start time of an event cannot be empty." +
"\n\t____________________________________________________________");
} else if (command.startsWith("event") && !command.contains("/to")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The end time of an event cannot be empty." +
"\n\t____________________________________________________________");
}
}

public void missingIndexException(String command) throws DukeException {
if (command.equals("mark")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to mark a task as done cannot be empty." +
"\n\t____________________________________________________________");
} else if (command.equals("unmark")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to unmark a task as not done cannot be empty." +
"\n\t____________________________________________________________");
} else if (command.equals("delete")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to delete a task as not done cannot be empty." +
"\n\t____________________________________________________________");
}
}

public void invalidIndexException(String command, int taskSize) throws DukeException {
if (command.startsWith("mark") || command.startsWith("unmark")
||command.startsWith("delete")) {
String index = command.split(" ")[1];
int index1 = Integer.parseInt(index);
if (index1 <= 0) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be zero or less." +
"\n\t____________________________________________________________");
} else if (index.equals("")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be empty." +
"\n\t____________________________________________________________");
} else if (index1 > taskSize) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be more than" +
" number of tasks." +
"\n\t____________________________________________________________");
}
}
}

public void invalidCommandException(String command) throws DukeException {
if (!command.startsWith("event") || !(command.startsWith("deadline")) ||
!command.startsWith("todo") || command.startsWith("mark") ||
!command.startsWith("unmark")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! I'm sorry, but I don't know what that means :-(" +
"\n\t____________________________________________________________");
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DukeException extends Exception {
DukeException(String message) {
super(message);
}
}
69 changes: 69 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class Event extends Task {
private final String taskType;
private final String eventStartTime;
private final String eventEndTime;

Event(int taskNumber, boolean taskStatus, String task,
String eventStartTime, String eventEndTime, int totalNumOfTasks) {
super(taskNumber, taskStatus, task, totalNumOfTasks);
this.taskType = "[E]";
this.eventStartTime = eventStartTime;
this.eventEndTime = eventEndTime;
}

@Override
public void markAsDone() {
System.out.println("\t____________________________________________________________" +
"\n\t Nice! I've marked this task as done:\n" +
"\t " + this.taskType + "[X]" + " " + super.task +
" (from: " + this.eventStartTime + " to: "
+ this.eventEndTime +
"\n\t____________________________________________________________");
}

@Override
public void unmarkAsUndone() {
System.out.println("\t____________________________________________________________" +
"\n\t OK, I've marked this task as not done yet:\n" +
"\t " + this.taskType + "[ ]" + " " + super.task +
" (from: " + this.eventStartTime + " to: "
+ this.eventEndTime +
"\n\t____________________________________________________________");
}

public void printEventTask() {
System.out.println("\t____________________________________________________________" +
"\n\t Got it. I've added this task:" +
"\n\t [E]" + super.getTaskStatus() + " " + super.task +
"(from: " + this.eventStartTime + " to: " + this.eventEndTime + ")" +
"\n\t Now you have " + super.totalNumOfTasks + " tasks in the list." +
"\n\t____________________________________________________________");
}

@Override
public void printDelete() {
int newTotalNumOfTasks = super.totalNumOfTasks - 1;
System.out.println("\t____________________________________________________________" +
"\n\t Noted. I've removed this task:" +
"\n\t " + this.taskType +
super.getTaskStatus() + " " + super.task + " (from: " + this.eventStartTime +
" to: " + this.eventEndTime + ")" + "\n\t Now you have " +
newTotalNumOfTasks + " tasks in the list." +
"\n\t____________________________________________________________");
}

@Override
public String getTaskType() {
return this.taskType;
}

@Override
public String getEventStartTime() {
return this.eventStartTime;
}

@Override
public String getEventEndTime() {
return this.eventEndTime;
}
}
Loading