Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cbf3cd2
Add Greet
vincentlauhl Aug 18, 2021
91ce339
Add echo and method for printing output
vincentlauhl Aug 25, 2021
e4f50de
Add list keeping and list printing
vincentlauhl Aug 25, 2021
39dbc7c
Add Task class and Mark as Done feature
vincentlauhl Aug 25, 2021
b287fd9
Change taskList to tasks
vincentlauhl Aug 25, 2021
b6db002
Change constant to upper case
vincentlauhl Aug 27, 2021
ab47db6
Add Event, ToDo, Deadline class and TaskType enum.
vincentlauhl Sep 1, 2021
026be10
Add text UI testing
vincentlauhl Sep 1, 2021
5da062e
Update text ui test and done refactoring
vincentlauhl Sep 1, 2021
14a2865
Add exception handling and exception class
vincentlauhl Sep 8, 2021
8d6b1e5
Change input and expected text for ui test
vincentlauhl Sep 8, 2021
42969c1
Move classes into packages and update runtest.bat
vincentlauhl Sep 8, 2021
46c8930
Merge branch 'branch-Level-5'
vincentlauhl Sep 8, 2021
8493d64
Add package duke and update readme and runtest.bat
vincentlauhl Sep 10, 2021
974df0a
Merge branch 'branch-A-Packages'
vincentlauhl Sep 10, 2021
3dc210f
Change array to array list, tidy up code, and update text ui test.
vincentlauhl Sep 15, 2021
a9902e7
Add delete task and update text ui test
vincentlauhl Sep 15, 2021
7c89dda
Add save to file after termination and read from file when the progra…
vincentlauhl Sep 15, 2021
b9b174f
Merge branch 'branch-Level-6'
vincentlauhl Sep 15, 2021
c254470
Merge branch 'branch-Level-7'
vincentlauhl Sep 15, 2021
80a19f2
Add help message and add jar file
vincentlauhl Sep 15, 2021
c2ec413
Add classes for OOP with main code untouched
vincentlauhl Sep 25, 2021
bcb0f12
Update the code to have OOP style
vincentlauhl Sep 25, 2021
10ef049
Add date and time for event and deadline and some constants
vincentlauhl Sep 26, 2021
861e928
Add find function to find tasks containining the description
vincentlauhl Sep 26, 2021
d76441c
Add javadocs to most classes and methods
vincentlauhl Sep 27, 2021
f01e19e
Merge pull request #1 from vincentlauhl/branch-Level-8
vincentlauhl Sep 27, 2021
7200398
Merge branch 'master' into branch-Level-9
vincentlauhl Sep 27, 2021
c0a0767
Merge pull request #2 from vincentlauhl/branch-Level-9
vincentlauhl Sep 27, 2021
54f9efa
Merge branch 'master' into branch-A-JavaDoc
vincentlauhl Sep 27, 2021
ca92735
Merge pull request #3 from vincentlauhl/branch-A-JavaDoc
vincentlauhl Sep 27, 2021
45dc063
Update ReadMe file
vincentlauhl Sep 29, 2021
540a897
Do a minor change on the ReadMe file
vincentlauhl Sep 29, 2021
31cc2eb
Update ReadMe to correct GitHub Page ReadMe
vincentlauhl Sep 29, 2021
6f942e9
Correct GitHub Page ReadMe
vincentlauhl Sep 29, 2021
69ce26d
Correct GitHub Page not bolding words
vincentlauhl Sep 29, 2021
086b7ec
Correct GitHub Page not bolding words attempt 2.
vincentlauhl Sep 29, 2021
4663af3
Update doc/ReadMe and revert the other ReadMe. Update help mesage
vincentlauhl Sep 29, 2021
266610b
Slight change to doc/ReadMe
vincentlauhl Sep 29, 2021
c1dd736
Update code to adhere to coding standards. Update error message.
vincentlauhl Sep 29, 2021
2157f69
Include error handling for general errors in reading file
vincentlauhl Sep 29, 2021
4ebd498
Correction on reused code format
vincentlauhl Oct 5, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
1. If there are any further prompts, accept the defaults.
1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).<br>
In the same dialog, set the **Project language level** field to the `SDK default` option.
3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output:
3. After that, locate the `src/main/java/duke/Duke.java` file, right-click it, and choose `Run duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output:
```
Hello from
____ _
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

227 changes: 227 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
package duke;

import task.Deadline;
import task.Event;
import task.Task;
import task.TaskType;
import task.ToDo;

import java.util.Scanner;

public class Duke {
public static final String DIVIDER = "___________________________________________________________";
public static final String INDENTATION = " ";
public static final String LOGO = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
public static final String HELLO_MESSAGE_2 = "Hello! I'm Duke, your friendly neighbourhood task manager";
public static final String HELLO_MESSAGE_3 = "What can I do for you? :D";
public static final String TASK_COMPLETED_MESSAGE = "You've completed the task! Well done!";
public static final String ADDED_TO_LIST = "I've added this to your list :D";
public static final String DEADLINE_DESCRIPTION_AND_DATE_SPLITTER = " /by ";
public static final String EVENT_DESCRIPTION_AND_DATE_TIME_SPLITTER = " /at ";
public static final String GOODBYE_MESSAGE = "Bye, hope to see you again soon! :)";
public static final String TYPE_SUITABLE_COMMAND_MESSAGE = "Sorry, I don't know what you mean. " +
"Please give me a suitable command :)";
public static final int TODO_STARTING_INDEX = 5;
public static final int DEADLINE_STARTING_INDEX = 9;
public static final int EVENT_STARTING_INDEX = 6;
public static final String PROMPT_TASK_DESCRIPTION = "Please tell me what do you need to do :)";
public static final String INPUT_MORE_THAN_NUMBER_OF_TASKS = "Woah, you don't have THAT many things to do!";
public static final String LIST_IS_EMPTY = "You're a free man :)";
public static final String MISSING_ARGUMENTS_FOR_EVENT_AND_DEADLINE = "Sorry," +
" you're missing some arguments, do type 'help' if you're unsure :)";
public static final String PROMPT_TASK_NUMBER = "Please tell me which task you finished :)";
public static final String PROMPT_SENSIBLE_INDEX = "Please give a number between 1-100 :)";
public static Task[] tasks = new Task[100];

public static void main(String[] args) {
printStartingMessage();
Scanner in = new Scanner(System.in);
String input = in.nextLine();
while (!input.equals("bye")) {
processInput(input);
input = in.nextLine();
}
printGoodbyeMessage();
}

public static void printIndentationAndDivider() {
System.out.print(INDENTATION);
System.out.println(DIVIDER);
}

public static void printWordsWithIndentation(String words) {
System.out.print(INDENTATION);
System.out.println(words);
}

private static void printStartingMessage() {
System.out.println("Hello from\n" + LOGO);
printIndentationAndDivider();
printWordsWithIndentation(HELLO_MESSAGE_2);
printWordsWithIndentation(HELLO_MESSAGE_3);
printIndentationAndDivider();
System.out.println();
}

private static void printGoodbyeMessage() {
printIndentationAndDivider();
printWordsWithIndentation(GOODBYE_MESSAGE);
printIndentationAndDivider();
}

private static void processInput(String input) {
switch(input.split(" ")[0].toLowerCase()) {
case "list":
executeListCase();
break;
case "done":
try {
executeDoneCase(input);

} catch (NullPointerException error) {
printErrorMessage(INPUT_MORE_THAN_NUMBER_OF_TASKS);

} catch (DukeException error) {
printErrorMessage(PROMPT_TASK_NUMBER);

} catch (ArrayIndexOutOfBoundsException error) {
printErrorMessage(PROMPT_SENSIBLE_INDEX);

} catch (NumberFormatException error) {
printErrorMessage(PROMPT_SENSIBLE_INDEX);

}
break;
case "todo":
try {
executeTaskCase(input, TODO_STARTING_INDEX, TaskType.TODO);

Choose a reason for hiding this comment

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

Suggest to keep consistent the new line convention throughout the code.

} catch (StringIndexOutOfBoundsException error) {
printErrorMessage(PROMPT_TASK_DESCRIPTION);
}
break;
case "deadline":
try {
executeTaskCase(input, DEADLINE_STARTING_INDEX,TaskType.DEADLINE);

} catch (StringIndexOutOfBoundsException error) {
printErrorMessage(PROMPT_TASK_DESCRIPTION);

}
break;
case "event":
try {
executeTaskCase(input, EVENT_STARTING_INDEX,TaskType.EVENT);

} catch (StringIndexOutOfBoundsException error) {
printErrorMessage(PROMPT_TASK_DESCRIPTION);
}
break;
default:
printErrorMessage(TYPE_SUITABLE_COMMAND_MESSAGE);
}
}

private static void printTaskMessage() {
printIndentationAndDivider();
printWordsWithIndentation(ADDED_TO_LIST);
printWordsWithIndentation(tasks[Task.getTotalTasks() - 1].getStatusIconAndDescription());
printWordsWithIndentation(notifyNumberOfTasks());
printIndentationAndDivider();
System.out.println();
}

private static void printErrorMessage(String error_message) {
printIndentationAndDivider();
printWordsWithIndentation(error_message);
printIndentationAndDivider();
System.out.println();
}

private static void executeTaskCase(String input, int starting_index, TaskType type) {
String description = input.strip().substring(starting_index);
try {
addTask(description, type);
printTaskMessage();

} catch (DukeException error) {
printErrorMessage(MISSING_ARGUMENTS_FOR_EVENT_AND_DEADLINE);
}
}

private static String[] parseInputForDifferentTask(String input,TaskType type) {
String[] parsedOutput = {};
switch(type) {
case TODO:
parsedOutput = new String[]{input};
break;
case DEADLINE:
parsedOutput = input.split(DEADLINE_DESCRIPTION_AND_DATE_SPLITTER);
break;
case EVENT:
parsedOutput = input.split(EVENT_DESCRIPTION_AND_DATE_TIME_SPLITTER);
break;
}
return parsedOutput;
}

private static void addTask(String input,TaskType type) throws StringIndexOutOfBoundsException, DukeException {

Choose a reason for hiding this comment

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

Suggest to relocate the function definition from "throw" onwards to a new line with appropriate line indent.

String[] parsedOutput = parseInputForDifferentTask(input,type);
switch(type){
case TODO:
tasks[Task.getTotalTasks()] = new ToDo(parsedOutput[0]);
break;
case EVENT:
if(parsedOutput.length < 2) {

Choose a reason for hiding this comment

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

Suggest to replace magic number with a well-named constant.

throw new DukeException();
}
tasks[Task.getTotalTasks()] = new Event(parsedOutput[0], parsedOutput[1]);
break;
case DEADLINE:
if(parsedOutput.length < 2) {
throw new DukeException();
}
tasks[Task.getTotalTasks()] = new Deadline(parsedOutput[0], parsedOutput[1]);
break;
}
Task.setTotalTasks(Task.getTotalTasks() + 1);
}

private static String notifyNumberOfTasks() {
return "Now you have " + Task.getTotalTasks() + " task(s) in the list";
}

private static void executeDoneCase(String input) throws NullPointerException,DukeException,
ArrayIndexOutOfBoundsException, NumberFormatException{
if(input.length() < 6) {
throw new DukeException();
}
int index = Integer.parseInt(input.split(" ")[1]) - 1;

Choose a reason for hiding this comment

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

Suggest to replace magic number with a well named constant.

tasks[index].markAsDone();
printTaskCompletedMessage(tasks[index]);
}

private static void printTaskCompletedMessage(Task task) {
printIndentationAndDivider();
printWordsWithIndentation(TASK_COMPLETED_MESSAGE);
printWordsWithIndentation(task.getStatusIconAndDescription());
printIndentationAndDivider();
System.out.println();
}

private static void executeListCase() {
printIndentationAndDivider();
if(Task.getTotalTasks() == 0) {
printWordsWithIndentation(LIST_IS_EMPTY);
}
for (int i = 0; i < Task.getTotalTasks(); i++) {
printWordsWithIndentation(i + 1 + "." + tasks[i].getStatusIconAndDescription());

Choose a reason for hiding this comment

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

Suggest to relocate expression in function argument to a separate line with appropriate comments.

}
printIndentationAndDivider();
System.out.println();
}
}
4 changes: 4 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package duke;

public class DukeException extends Exception{
}
17 changes: 17 additions & 0 deletions src/main/java/task/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package task;

public class Deadline extends Task{
public static final String BY = "by: ";
protected String date;
private static final String IDENTIFIER = "D";

public Deadline(String description,String date) {
super(description);
this.date = date;
}

public String getStatusIconAndDescription() {
String icon = (isDone ? "X" : " ");
return addSquareBrackets(IDENTIFIER) + addSquareBrackets(icon) + " " + description + " " + addBrackets(BY + date);
}
}
17 changes: 17 additions & 0 deletions src/main/java/task/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package task;

public class Event extends Task{
public static final String AT = "at: ";
protected String dateAndTime;
private static final String IDENTIFIER = "E";

public Event(String description, String dateAndTime) {
super(description);
this.dateAndTime = dateAndTime;
}

public String getStatusIconAndDescription() {
String icon = (isDone ? "X" : " ");
return addSquareBrackets(IDENTIFIER) + addSquareBrackets(icon) + " " + description + " " + addBrackets(AT + dateAndTime);
}
}
41 changes: 41 additions & 0 deletions src/main/java/task/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package task;

public class Task {
protected boolean isDone;
protected String description;

private static int totalTasks = 0;

public Task(String description){
this.description = description;
isDone = false;
}

public String getStatusIconAndDescription() {
String icon = (isDone ? "X" : " ");
return addSquareBrackets(icon) + " " + description;
}

public void markAsDone() {
isDone = true;
}

public void setDescription(String description) {
this.description = description;
}

public static int getTotalTasks() {
return totalTasks;
}

public static void setTotalTasks(int totalTasks) {
Task.totalTasks = totalTasks;
}

protected static String addSquareBrackets(String s) {
return "[" + s + "]";
}
protected static String addBrackets(String s) {
return "(" + s + ")";
}
}
5 changes: 5 additions & 0 deletions src/main/java/task/TaskType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package task;

public enum TaskType {
TODO,DEADLINE,EVENT;
}
14 changes: 14 additions & 0 deletions src/main/java/task/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package task;

public class ToDo extends Task{
private static final String IDENTIFIER = "T";

public ToDo(String description) {
super(description);
}

public String getStatusIconAndDescription() {
String icon = (isDone ? "X" : " ");
return addSquareBrackets(IDENTIFIER) + addSquareBrackets(icon) + " " + description;
}
}
Loading