Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
60a88c0
Level-0: Greet
zh1huang Aug 15, 2021
8747f62
Level-1
zh1huang Aug 25, 2021
ab4602c
Level 2
zh1huang Aug 25, 2021
b43adfa
Level-3
zh1huang Aug 25, 2021
68d69b3
A-CodingStandard
zh1huang Aug 26, 2021
c3cd436
Minor typo changes
zh1huang Aug 26, 2021
6b63884
Level-4
zh1huang Sep 2, 2021
9089498
A-CodeQuality
zh1huang Sep 2, 2021
5aab948
Level 5. Handle Errors
zh1huang Sep 8, 2021
5d11a58
bug fix
zh1huang Sep 8, 2021
aa34d61
Merge branch 'master' into branch-Level-5
zh1huang Sep 8, 2021
753e0a8
Formatting issues
zh1huang Sep 9, 2021
eea7087
Merge branch 'branch-Level-5'
zh1huang Sep 9, 2021
b6f0c99
Merge commit '753e0a8d9f752011003db89b100898f179545b01'
zh1huang Sep 9, 2021
326a6f2
Refactor packages
zh1huang Sep 10, 2021
04badc3
Merge branch 'branch-A-Packages'
zh1huang Sep 10, 2021
30ba786
Add Increment: Level-6 Delete
zh1huang Sep 14, 2021
22b68f0
Merge branch 'branch-Level-6'
zh1huang Sep 15, 2021
3a8a6f4
Cleaned up TaskManager
zh1huang Sep 15, 2021
793418f
Level-7: Save
zh1huang Sep 16, 2021
44695ee
Merge branch 'branch-Level-7'
zh1huang Sep 16, 2021
5cf8dd0
add manifest file
zh1huang Sep 16, 2021
6b52c9e
Bugfix of loading of tasks from file
zh1huang Sep 16, 2021
3d92406
Finalise and clean up Storage class
zh1huang Sep 28, 2021
054a4d6
Added Parser class
zh1huang Sep 28, 2021
770747e
Added Find
zh1huang Sep 28, 2021
99938ba
Added JavaDocs
zh1huang Sep 28, 2021
0b0382a
Merge pull request #1 from zh1huang/branch-Level-9
zh1huang Sep 28, 2021
258e217
Merge branch 'master' into A-JavaDoc
zh1huang Sep 28, 2021
25f9be6
Merge pull request #2 from zh1huang/A-JavaDoc
zh1huang Sep 28, 2021
433daa2
Testing user guide
zh1huang Sep 29, 2021
c89f1a9
test
zh1huang Sep 29, 2021
86057c2
test user guide
zh1huang Sep 29, 2021
60db3bb
Finalise User Guide
zh1huang Sep 29, 2021
b89640a
Final touching up
zh1huang Sep 30, 2021
8fbb849
Update README.md
zh1huang Oct 1, 2021
1e3f1a9
Update README.md
zh1huang Oct 1, 2021
e99c7f8
Update README.md
zh1huang Oct 1, 2021
ab2da15
Update README.md
zh1huang Oct 1, 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
22 changes: 22 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Deadline extends Task {

protected String by;

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

public String getIcon() {
return "[D]";
}

public String getBy() {
return "(by:" + by + ")";
}

@Override
public String toString() {
return getIcon() + super.toString() + "(by:" + by + ")";
}
}
12 changes: 6 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import java.util.Scanner;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
TaskManager taskManager = new TaskManager();
Scanner scanner = new Scanner(System.in);
Ui ui = new Ui(taskManager, scanner);
ui.start();
Comment on lines +5 to +
Copy link

Choose a reason for hiding this comment

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

I like how you created a taskManager class to handle the commands and an Ui class to handle all the output, making the code very easy to understand.

}
}
20 changes: 20 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Event extends Task{
protected String at;

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

public String getIcon() {
return "[E]";
}
public String getAt() {
return "(at:" + at + ")";
}

@Override
public String toString() {
return getIcon() + super.toString() + "(at:" + at + ")";
}
}
33 changes: 33 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class Task {
protected String description;
protected boolean isDone;

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

public void taskDone() {
this.isDone = true;
}

public String getStatusIcon() {
return (isDone ? "[X]" : "[ ]");
}
public String getIcon() {
return "";
}
public String getBy() {
return "";
}
public String getAt() {
return "";
}

Choose a reason for hiding this comment

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

It might be better to have a blank line among each function.

Choose a reason for hiding this comment

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

I agree. It may be minor but it can help make the functions look more distint and clear.


public String toString() {
return getStatusIcon() + " " + this.description ;
}


}
129 changes: 129 additions & 0 deletions src/main/java/TaskManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import java.util.ArrayList;

public class TaskManager {
private ArrayList<Task> taskList;

public TaskManager() {
this.taskList = new ArrayList<>();
}

/**
* Adds task to taskList ArrayList
*
* @param task Task to be checked
*/
public void add(String task) {
String taskType = getCommand(task);
Task newTask;
String description = getDescription(task);
switch(taskType) {
Copy link

Choose a reason for hiding this comment

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

I like how you named the variables, very intuitive and easy to understand.

case "todo":
newTask = new ToDo(description);
taskList.add(newTask);
break;
case "deadline":
String by = getDate(task);
newTask = new Deadline(description, by);
taskList.add(newTask);
break;
case "event":
String at = getDate(task);
newTask = new Event(description, at);
taskList.add(newTask);
break;
default:
System.out.println(" Invalid command, please try again");
return;
}

Choose a reason for hiding this comment

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

Perhaps you can make this block of code separate from the few lines above it?


System.out.println(" Got it. I've added this task:\n " + newTask);
printSize();
}

/**
* Checks if specified task is done
*
* @param taskNumber task number of task to be checked
*/
public void checkDone(int taskNumber) {
taskList.get(taskNumber - 1).taskDone();
}

public String getDescription(String task) {
String description;
int separator;
if (getCommand(task).equals("todo")) {
description = task.substring(5);
} else if (getCommand(task).equals("deadline")) {
separator = task.indexOf("/by");
description = task.substring(9, separator);
} else if (getCommand(task).equals("event")){
separator = task.indexOf("/at");
description = task.substring(6, separator);
} else {
description = null;
}
return description;
}

public String getCommand(String task) {
String[] command = task.split(" ");
String taskType = command[0];

return taskType;
}
public void printSize() {
if (getSize() == 1) {
System.out.println(" Now you have " + 1 + " task in the list.");
} else {
System.out.println(" Now you have " + getSize() + " tasks in the list.");
}

Choose a reason for hiding this comment

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

Minor style and language taken care of. Nice!

}

/**
* Returns name of task given task number
*
* @param index index of task in taskList ArrayList
* @return Name of Task
*/
public String getName(int index) {
return taskList.get(index - 1).toString();
}



public int getSize() {
return taskList.size();
}


public void list() {
for (int i = 0; i < taskList.size(); i++) {
Task t = taskList.get(i);
if (t.getIcon().equals("[D]")) {
System.out.println(" " + (i + 1) + "." + t);
} else if (t.getIcon().equals("[E]")) {
System.out.println(" " + (i + 1) + "." + t);
} else {
System.out.println(" " + (i + 1) + "." + t);
}
}
}



public String getDate(String description) {
String date;
if (description.contains("/by")) {
int indexOfSeparator = description.indexOf("/by");
date = description.substring(indexOfSeparator + 3);
} else if (description.contains("/at")) {
int indexOfSeparator = description.indexOf("/at");
date = description.substring(indexOfSeparator + 3);
} else {
date = null;
}
return date;
}

}
13 changes: 13 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class ToDo extends Task{
public ToDo(String description) {
super(description);
}

public String getIcon() {
return "[T]";
}
@Override
public String toString() {
return getIcon() + super.toString();
}
}
58 changes: 58 additions & 0 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.util.Scanner;

public class Ui {
private TaskManager taskManager;
private Scanner scanner;

public Ui(TaskManager taskManager, Scanner scanner) {
this.taskManager = taskManager;
this.scanner = scanner;
}

public void start() {
String lineBreak = " ____________________________________________________________\n";
String logo = "\n" +
" \n" +
" ,--. ,------. ,--. ,--. ,--. \n" +
",-' '-.,---.| .-. \\ ,---.| | `--',---,-' '-. \n" +
"'-. .-| .-. | | \\ | .-. | | ,--( .-'-. .-' \n" +
" | | ' '-' | '--' ' '-' | '--| .-' `)| | \n" +
" `--' `---'`-------' `---'`-----`--`----' `--' \n" +
" \n";

Choose a reason for hiding this comment

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

interesting twist to the Duke java graphic provided with the starting template!

String greetings = lineBreak
+ logo
+ " Welcome to the toDoList Chatbot\n"
+ " What would you like to do today?\n"
+ lineBreak;
String farewell = " Bye. Hope to see you again soon!";
System.out.println(greetings);

while (true) {
String input = scanner.nextLine();
String[] command = input.split(" ");
String firstWord = command[0];
//Task t = new Task(input);

System.out.print(lineBreak);
switch (firstWord) {
case "bye":
System.out.println(farewell);
return;
case "list":
System.out.println(" Here are the tasks in your list:");
taskManager.list();
break;
case "done":
System.out.println(" Nice! I've marked this task as done: ");
int taskNumber = Integer.parseInt(command[1]);
taskManager.checkDone(taskNumber);
System.out.println(" " + taskManager.getName(taskNumber));
break;

default:
taskManager.add(input);
}
System.out.print(lineBreak);
}
}
}
Copy link

Choose a reason for hiding this comment

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

Overall I really like how you have broken down everything into classes. I think it is very good OOP. Perhaps add some javadocs to explain some of the methods?