Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8bf8991
add increment level 0
silinche Aug 20, 2021
5876d3a
added increment 1
silinche Aug 25, 2021
02672d8
added increment 2
silinche Aug 25, 2021
d75ba2c
added increment 3
silinche Aug 25, 2021
c77d04f
fix minor bug for increment 3
silinche Aug 25, 2021
308eacf
update on A-CodingStandard
silinche Aug 25, 2021
97a6781
Increment 4
silinche Sep 1, 2021
64e85b9
fixed bugs for level-4
silinche Sep 1, 2021
48ce882
fixed minor bugs for increment level 4
silinche Sep 1, 2021
653a21d
commit text ui testing
silinche Sep 8, 2021
7f61f2d
create more functions to comply with code quality standards
silinche Sep 15, 2021
dfcf04b
added dealing with errors
silinche Sep 15, 2021
ccd2556
Merge branch 'branch-Level-5'
silinche Sep 15, 2021
b4c1c68
added packaging
silinche Sep 15, 2021
7f4ad3f
added level 6 deletion function
silinche Sep 16, 2021
06d40a3
added the save to file feature
silinche Sep 17, 2021
d308886
Merge branch 'branch-Level-6'
silinche Sep 17, 2021
2c8103d
Merge branch 'branch-Level-7'
silinche Sep 17, 2021
2a89619
created Storage class to achieve more oop
silinche Sep 28, 2021
d41de47
added ui class to achieve more oop
silinche Sep 28, 2021
3e52e94
added more classes to achieve more oop
silinche Sep 28, 2021
8320297
added the find feature (level 9)
silinche Sep 29, 2021
fd35808
added javadoc
silinche Oct 1, 2021
c492a3b
Merge pull request #1 from silinche/branch-Level-9
silinche Oct 1, 2021
e61603d
Merge branch 'master' into branch-A-JavaDoc
silinche Oct 1, 2021
1e115d9
Merge pull request #2 from silinche/branch-A-JavaDoc
silinche Oct 1, 2021
2faad66
Merge branch 'master' of https://github.com/silinche/ip
silinche Oct 1, 2021
bb57228
Added user guide
silinche Oct 1, 2021
ebba67b
Set theme jekyll-theme-cayman
silinche Oct 1, 2021
999995d
fixed issues with saving in files
silinche Oct 1, 2021
4168e98
Merge branch 'master' of https://github.com/silinche/ip
silinche 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Duke project template
# duke.command.Duke project template

This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it.

Expand All @@ -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.command.Duke.java` file, right-click it, and choose `Run duke.command.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.

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

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

import java.util.Scanner;


public class Duke {
public static void listOut(Task[] tasks, int taskNumber) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using a clearer naming convention for your method such as printTasks().

for (int i = 0; i < taskNumber; i++) {
System.out.println((i + 1) + "." + tasks[i]);
}
}

public static void markDone(String line, Task[] tasks) {
try {
int index = Integer.parseInt(line.substring(5)) - 1;
tasks[index].setDone();
System.out.println("Nice! I've marked this task as done:");
System.out.println(" " + tasks[index].getStatusIcon() + " " + tasks[index].getDescription());
} catch (StringIndexOutOfBoundsException e) {
System.out.println("OOPS!!! The description of a mark-done cannot be empty.");
}
}

public static boolean addTodo(String line, Task[] tasks, int taskNumber) {
try {
tasks[taskNumber] = new ToDo(line.substring(5));
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);
System.out.println("Now you have " + taskNumber + " tasks in the list");
return true;
} catch (StringIndexOutOfBoundsException e) {
System.out.println("OOPS!!! The description of a todo cannot be empty.");
return false;
}
}

public static boolean addDeadline(String line, Task[] tasks, int taskNumber) {
String[] words = line.split(" ");
int index = 0;
String deadlineDescription = "";
String by = "";
for (int i = 0; i < words.length; i++) {
if (words[i].equals("/by")) {
index = i;
break;
}
}
if (index == 0) {
System.out.println("OOPS!!! The description of a deadline cannot be empty.");
return false;
}
for (int i = 1; i < index; i++) {
deadlineDescription = deadlineDescription + words[i] + " ";
}
for (int i = index + 1; i < words.length; i++) {
by = by + words[i] + " ";
}
tasks[taskNumber] = new Deadline(deadlineDescription, by);
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 1]);
System.out.println("Now you have " + taskNumber + " tasks in the list");
return true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You may want to consider splitting this method into multiple smaller methods that do smaller tasks and call it from this method. This goes the same for the other tasks-related methods.

}

public static boolean addEvent(String line, Task[] tasks, int taskNumber) {
String[] words = line.split(" ");
int index = 0;
String eventDescription = "";
String at = "";
for (int i = 0; i < words.length; i++) {
if (words[i].equals("/at")) {
index = i;
break;
}
}
if (index == 0) {
System.out.println("OOPS!!! The description of a deadline cannot be empty.");
return false;
}
for (int i = 1; i < index; i++) {
eventDescription = eventDescription + words[i] + " ";
}
for (int i = index + 1; i < words.length; i++) {
at = at + words[i] + " ";
}
tasks[taskNumber] = new Event(eventDescription, at);
taskNumber++;
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks[taskNumber - 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.

Should the magic literal 1 be declared as a constant instead so that it is easier for you and other programmers to refer to your code in the future? This applies to all magic literals across the code.

System.out.println("Now you have " + taskNumber + " tasks in the list");
return true;
}

public static void sayHi() {
System.out.println("Hello I'm duke.command.Duke");
System.out.println("What can I do for you?");
}

public static void sayBye() {
System.out.println("Bye. Hope to see you again soon!");
}

public static void running() {
Task[] tasks = new Task[100];
int taskNumber = 0;
String line;
Scanner in = new Scanner(System.in);
while (true) {
line = in.nextLine();
if (line.equals("bye")) {
return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In general, we do not use a return statement in a void function. If you want to break out of the current loop, use the "break" statement instead.

}
if (line.equals("list")) {
listOut(tasks, taskNumber);
} else if (line.startsWith("done")) {
markDone(line, tasks);
} else if (line.startsWith("todo")) {
if (addTodo(line, tasks, taskNumber)) {
taskNumber++;
}
} else if (line.startsWith("deadline")) {
if (addDeadline(line, tasks, taskNumber)) {
taskNumber++;
}
} else if (line.startsWith("event")) {
if (addEvent(line, tasks, taskNumber)) {
taskNumber++;
}
} else {
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}
Comment on lines +115 to +38
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could consider splitting this functionality into another method for better readability and reusability of your code.

}

public static void main(String[] args) {
sayHi();
running();
sayBye();
}
}
16 changes: 16 additions & 0 deletions src/main/java/duke/task/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package duke.task;

public class Deadline extends Task {

protected String by;

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

@Override
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of the override statement. Well done!

public String toString() {
return "[D]" + super.toString() + "(by: " + by + ")";
}
}
16 changes: 16 additions & 0 deletions src/main/java/duke/task/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package duke.task;

public class Event extends Task {

protected String at;

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

@Override
public String toString() {
return "[E]" + super.toString() + "(at: " + at + ")";
}
}
28 changes: 28 additions & 0 deletions src/main/java/duke/task/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package duke.task;

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

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

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

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

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

@Override
public String toString() {
return this.getStatusIcon() + " " + this.getDescription();
}
}
12 changes: 12 additions & 0 deletions src/main/java/duke/task/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package duke.task;

public class ToDo extends Task{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do take note of the spacing for each bracket and curly braces for the consistency of the whole program.

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

@Override
public String toString() {
return "[T]" + super.toString();
}
}
24 changes: 17 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Hello I'm duke.command.Duke
What can I do for you?
Got it. I've added this task:
[T][ ] do wct
Now you have 1 tasks in the list
Got it. I've added this task:
[D][ ] inquiry (by: now )
Now you have 2 tasks in the list
Got it. I've added this task:
[E][ ] wct (at: tomorrow 2pm )
Now you have 3 tasks in the list
Nice! I've marked this task as done:
[X] do wct
1.[T][X] do wct
2.[D][ ] inquiry (by: now )
3.[E][ ] wct (at: tomorrow 2pm )
Bye. Hope to see you again soon!
6 changes: 6 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
todo do wct
deadline inquiry /by now
event wct /at tomorrow 2pm
done 1
list
bye