Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1e3655a
level 1
Shizheng001 Feb 2, 2021
49ee517
Level 2
Shizheng001 Feb 2, 2021
5ebbd23
Level 3
Shizheng001 Feb 2, 2021
1675a38
Level 4
Shizheng001 Feb 2, 2021
80e2e5c
Level 5
Shizheng001 Feb 2, 2021
dd46e6e
Level 6
Shizheng001 Feb 2, 2021
6663e80
add graddle support
Shizheng001 Mar 7, 2021
5c10cf2
OOP and Jar
Shizheng001 Mar 7, 2021
5d6c844
Merge pull request #2 from Shizheng001/Jar
Shizheng001 Mar 7, 2021
7672a13
Level 9
Shizheng001 Mar 22, 2021
a0a85c8
Use CheckStyle
Shizheng001 Mar 22, 2021
e295557
add-gradle-support
Shizheng001 Mar 22, 2021
8b15dd1
Merge pull request #3 from Shizheng001/Use_CheckStyle
Shizheng001 Mar 22, 2021
33d72f8
Add JavaDoc comments
Shizheng001 Mar 22, 2021
84ce18f
A better Gui.
Shizheng001 Mar 22, 2021
ec32cf3
Merge pull request #4 from Shizheng001/A_better_Gui
Shizheng001 Mar 22, 2021
7559aec
A better Gui.
Shizheng001 Mar 22, 2021
20d5fc5
Merge pull request #5 from Shizheng001/A_better_Gui
Shizheng001 Mar 22, 2021
f50d7d8
Added userguide
Shizheng001 Mar 22, 2021
7baa86b
Merge pull request #6 from Shizheng001/A-UserGuide
Shizheng001 Mar 22, 2021
5032f29
Added userguide
Shizheng001 Mar 22, 2021
53fbf79
Added userguide new
Shizheng001 Mar 22, 2021
09a6d02
Merge pull request #7 from Shizheng001/A-UserGuide
Shizheng001 Mar 22, 2021
66a7bff
Added userguide updates v2
Shizheng001 Mar 22, 2021
58bb224
Merge pull request #8 from Shizheng001/A-UserGuide
Shizheng001 Mar 22, 2021
6e4fa72
adding files
Shizheng001 Mar 22, 2021
97d2238
further edits 1
Shizheng001 Mar 22, 2021
fb11842
Merge pull request #9 from Shizheng001/A-CodeQuality
Shizheng001 Mar 22, 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
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadline extends Task {

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

public Deadline(String description, boolean b) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

instead of using b, you could just use isDone.

super(description,b);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For greater readability, perhaps you could have a whitespace after the comma?

}

public String toString() {
return "[D]" + super.toString();
}
}
97 changes: 91 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,95 @@
import java.util.Scanner;
import java.util.ArrayList;

public class Duke {

/**
* main method to run the program
*
* @param args command line arguments taken in
*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor nitpick but perhaps consider starting Javadoc sentences with an uppercase letter and ending with a full stop to keep within the coding standard.

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
Scanner sc = new Scanner(System.in);
System.out.println("Hello! I'm Duke\n"+ "What can I do for you?");
ArrayList<Task> items = new ArrayList<>();

while (true) {
String input = sc.nextLine();
try {
errorHandling(input);
if (input.equals("bye")) {
bye();
break;
} else if (input.contains("done")) {
System.out.println("Nice! I've marked this task as done: ");

int taskNum = Integer.parseInt(input.substring(5));
String name = items.get(taskNum - 1).getDescription();

Task type = items.get(taskNum - 1);
items.remove(taskNum - 1);
if (type instanceof Todo) {
Todo markDone = new Todo(name, true);
items.add(taskNum - 1, markDone);
System.out.println(markDone);
} else if (type instanceof Deadline) {
Deadline markDone = new Deadline(name, true);
items.add(taskNum - 1, markDone);
System.out.println(markDone);
} else {
Event markDone = new Event(name, true);
items.add(taskNum - 1, markDone);
System.out.println(markDone);
}

} else if (input.equals("list")) {
int n = 1;
System.out.println("Here are the tasks in your list:");
for (Task item : items) {
System.out.println(n + ". " + item);
n++;
}

} else if (input.length() >= 8 && input.substring(0,8).equals("deadline")) {
items.add(new Deadline(input.substring(8)));
} else if (input.length() >= 4 && input.substring(0,4).equals("todo")) {
items.add(new Todo(input.substring(4)));
} else if (input.length() >= 5 && input.substring(0,5).equals("event")) {
items.add(new Event(input.substring(5)));
} else if (input.length() >= 6 && input.substring(0,6).equals("delete")) {
int taskToDelete = Integer.parseInt(input.substring(7));
Task toRemove = items.get(taskToDelete - 1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps int taskToDelete could be indexOfTaskToDelete even though it may be quite long.
It may help to distinguish it from Task toRemove.

items.remove(taskToDelete - 1);
System.out.println("Noted. I've removed this task:\n "
+ toRemove + "\nNow you have " + items.size() + " tasks in the list.");

} else {
items.add(new Task(input));
}
} catch (Exception e) {
System.out.println(e);
}
}
}

/**
* prints Goodbye message.
*/
public static void bye() {
System.out.println("Bye. Hope to see you again soon!");
}

public static void errorHandling(String input) throws DukeException {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Following the coding guidelines, method names should be verbs. Perhaps handleError() would be a better method name?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same sentiment as the above!

if (input.length() == 4 && input.equals("todo")) {
throw new DukeException(" ☹ OOPS!!! The description of a todo cannot be empty.");
} else if (input.length() == 8 && input.equals("deadline")) {
throw new DukeException(" ☹ OOPS!!! The description of a deadline cannot be empty.");
} else if (input.length() == 5 && input.equals("event")) {
throw new DukeException(" ☹ OOPS!!! The description of a event cannot be empty.");
} else if (input.length() >= 4 && input.substring(0,4).equals("blah")) {
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
} else if (input.isBlank()) {
throw new DukeException(" ☹ OOPS!!! A Task cannot be empty.");
} else {}
}
}
6 changes: 6 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class DukeException extends Exception {

public DukeException(String e) {
super(e);
}
}
14 changes: 14 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Event extends Task {
public Event(String description) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should there be an empty line before this constructor?
I notice that there are times you leave an empty line before constructors, and there are times you leave out the empty line.

super(description);
}

public Event(String description, boolean b) {
super(description,b);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps you could use isDone instead of b, so that it is more descriptive?

}

public String toString() {
return "[E]" + super.toString();
}
}

31 changes: 31 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Task {
protected String description;
protected boolean isDone;

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

public Task(String description, boolean b) {
this.description = description;
this.isDone = b;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public String getDescription() {
return this.description;
}

public Task changeStatus(Task t) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this method is a setter, maybe setStatusTrue() would be better? It would explain to readers what status you are changing to as well!

return new Task(t.getDescription(), true);
}

public String toString() {
return "[" + getStatusIcon() + "]" + getDescription();

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

public Todo(String description, boolean b) {
super(description, b);
}

public String toString() {
return "[T]" + super.toString();
}
}


7 changes: 7 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
todo homework1
event lecture 1 (10.00am tmr)
deadline OP1cs2101 (16 Feb)

done 1
done 2
done 3
2 changes: 1 addition & 1 deletion text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REM delete output from previous run
if exist ACTUAL.TXT del ACTUAL.TXT

REM compile the code into the bin folder
javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java
javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\Duke.java
IF ERRORLEVEL 1 (
echo ********** BUILD FAILURE **********
exit /b 1
Expand Down