Skip to content
Open

iP #188

Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
0acc03a
Level-0
VishalJeyaram Aug 26, 2021
e5a6c76
echo commands entered by the user
VishalJeyaram Aug 26, 2021
73e933e
Add the ability to store whatever text entered by the user and displa…
VishalJeyaram Aug 26, 2021
9aa6701
Added the ability to mark tasks as done.
VishalJeyaram Aug 26, 2021
9d224de
Tweaked the code to comply with a coding standard
VishalJeyaram Aug 26, 2021
d10b249
Added support for tracking three types of tasks
VishalJeyaram Sep 2, 2021
431e205
Coding quality and standard improved
VishalJeyaram Sep 2, 2021
423e4b6
testing optimized
VishalJeyaram Sep 2, 2021
dd62bad
Testing commit
VishalJeyaram Sep 9, 2021
0fd82f9
fixing bugs
VishalJeyaram Sep 9, 2021
69645da
Merge branch 'master' into testbranch
VishalJeyaram Sep 9, 2021
f2d4394
printing statements fixed
VishalJeyaram Sep 9, 2021
0a70a2e
Line 118 printing formatting fixed
VishalJeyaram Sep 9, 2021
8235c1d
Merge branch 'testbranch'
VishalJeyaram Sep 9, 2021
199fc4c
Work in progress level 5
VishalJeyaram Sep 9, 2021
e893cef
Teach Duke to deal with errors such as incorrect inputs entered by th…
VishalJeyaram Sep 9, 2021
f0a5864
Merge branch 'branch-Level-5'
VishalJeyaram Sep 9, 2021
75c9f16
Divide classes into packages
VishalJeyaram Sep 9, 2021
f192e85
Merge branch 'branch-A-Packages'
VishalJeyaram Sep 9, 2021
b88ba29
Add support for deleting tasks from the list.
VishalJeyaram Sep 13, 2021
da1e49e
Add support for deleting tasks from the list. (latest)
VishalJeyaram Sep 13, 2021
23fdf30
Save the tasks in the hard disk automatically whenever the task list …
VishalJeyaram Sep 13, 2021
4643e21
Changed text file
VishalJeyaram Sep 13, 2021
d87aae0
Level 7 commit
VishalJeyaram Sep 14, 2021
9609e5f
Adding the text file
VishalJeyaram Sep 14, 2021
47dd64e
Level 7 final commit
VishalJeyaram Sep 14, 2021
95d1f4f
Added text file
VishalJeyaram Sep 14, 2021
692352e
Merge branch 'branch-Level-6'
VishalJeyaram Sep 14, 2021
d31772b
Merge branch 'branch-Level-7'
VishalJeyaram Sep 14, 2021
db8bd73
A-JAR
VishalJeyaram Sep 16, 2021
57a79f0
Updated master
VishalJeyaram Sep 20, 2021
8e7fd03
Minor edits to master
VishalJeyaram Sep 20, 2021
21c0704
Give users a way to find a task by searching for a keyword.
VishalJeyaram Sep 20, 2021
a1a550c
Teach Duke how to understand dates and times.
VishalJeyaram Sep 20, 2021
32656a1
Print out tasks which happened on a specified date
VishalJeyaram Sep 22, 2021
7306402
Date command updated
VishalJeyaram Sep 22, 2021
c50db4d
Merge pull request #1 from VishalJeyaram/branch-Level-8
VishalJeyaram Sep 22, 2021
a1ce7a1
Merge branch 'master' of https://github.com/VishalJeyaram/ip
VishalJeyaram Sep 22, 2021
52c2770
Merge branch 'master' into branch-Level-9
VishalJeyaram Sep 22, 2021
b32f9ed
Text file issue solved
VishalJeyaram Sep 22, 2021
a332d1a
Text file issue solved
VishalJeyaram Sep 22, 2021
7c7da8e
Merge pull request #2 from VishalJeyaram/branch-Level-9
VishalJeyaram Sep 22, 2021
ebf987f
Merge branch 'master' of https://github.com/VishalJeyaram/ip
VishalJeyaram Sep 22, 2021
2f8ce8d
Text file changed
VishalJeyaram Sep 22, 2021
5dce913
Merge branch 'branch-Level-8'
VishalJeyaram Sep 22, 2021
4561808
Added storage class halfway done
VishalJeyaram Sep 23, 2021
a3b5c81
Ui and tasklist updated
VishalJeyaram Sep 24, 2021
f16c13f
Task file updated
VishalJeyaram Sep 24, 2021
99cffd9
More OOP 90 percent implemented
VishalJeyaram Sep 26, 2021
55f4c5b
More OOP done
VishalJeyaram Sep 26, 2021
6310239
AJava Doc done
VishalJeyaram Sep 26, 2021
4e96b08
Bugs fixed and comments added
VishalJeyaram Sep 27, 2021
5a77160
A Java Doc Done
VishalJeyaram Sep 28, 2021
a1236a4
Text file changed
VishalJeyaram Sep 28, 2021
e6f1fd6
Merge branch 'master' into branch-A-JavaDoc
VishalJeyaram Sep 28, 2021
4f230f3
Merged Master and A-java doc
VishalJeyaram Sep 28, 2021
56fdebc
Merge pull request #3 from VishalJeyaram/branch-A-JavaDoc
VishalJeyaram Sep 28, 2021
a279691
Merge branch 'master' of https://github.com/VishalJeyaram/ip
VishalJeyaram Sep 28, 2021
6022a07
More OOP completed
VishalJeyaram Sep 28, 2021
d89f151
Exception erros changed
VishalJeyaram Sep 28, 2021
abf55fd
Class name changed and Ui messages updated
VishalJeyaram Sep 28, 2021
553b120
User Guide/README updated
VishalJeyaram Sep 30, 2021
9d2ea67
Set theme jekyll-theme-hacker
VishalJeyaram Sep 30, 2021
7154720
Updated Ui messages
VishalJeyaram Sep 30, 2021
effe27d
Merge branch 'master' of https://github.com/VishalJeyaram/ip
VishalJeyaram Sep 30, 2021
3b0adcf
Command summary table updated
VishalJeyaram Sep 30, 2021
55bc19a
Heading sizes updated for user guide
VishalJeyaram Sep 30, 2021
d2019f2
Hyperlinks for user guide updated
VishalJeyaram Sep 30, 2021
3bc240c
User guide sections separated
VishalJeyaram Sep 30, 2021
56bb844
Final changes made. Code quality improved.
VishalJeyaram Oct 1, 2021
ffa2789
Userguide final update
VishalJeyaram Oct 1, 2021
8cb4736
User guide final update
VishalJeyaram Oct 1, 2021
4466d03
Update README.md
VishalJeyaram Mar 3, 2025
b5a9282
Update README.md
VishalJeyaram Mar 3, 2025
b883ff9
Update README.md
VishalJeyaram Mar 3, 2025
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.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.Duke.java` file, right-click it, and choose `Run duke.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.

16 changes: 16 additions & 0 deletions src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package duke;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great to see that you organise your types (e.g., classes) into a package for easier management!


public class Deadline extends Task {

protected String by;

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

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

import java.util.Scanner;

public class Duke {

private static int byeFlag = 0;
private static int positionCheck = 0;
private static int SIZE = 100;
Copy link
Copy Markdown

@zikunz zikunz Sep 14, 2021

Choose a reason for hiding this comment

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

Great use of upper case letters for the final attribute!

Perhaps we can make this attribute (i.e., SIZE) final as well if it does not change? This also applies to all other attributes which do not change (e.g., various messages from line 10 onwards).

private static String EMPTY = "There is no data in your list master!";
private static String EXCEEDED = "Oh dear me! We have exceeded my system's maximum capacity!";
private static String UNSPECIFIED_DONE = "Oh no master, I am not quite sure which task you would like me to mark as done!";
private static String INVALID = "Please type in a valid number master! Type \"list\" to check the index number of your list data";
public static String DEADLINE_ERROR = ("Sorry Master! I don't think you have properly keyed in the parameters.\n" +
"Please enter \"deadline\", followed by the task, followed by \"/by\", \n" +
"and lastly followed by the due date to specify the deadline Master!");
public static String EVENT_ERROR = ("Sorry Master! I don't think you have properly keyed in the parameters. \n" +
"Please enter \"event\", followed by the event, followed by \"/at\", and \n" +
"lastly followed by the event duration to specify the timing of the event Master!");
public static String TODO_ERROR = ("Sorry Master! I don't think you have properly keyed in the parameters.\n" +
" Please enter \"todo\", followed by the task you wish to add to your \n" +
"duke.Todo list Master!");
public static String UNSPECIFIED_TASK = ("Sorry Master! Despite the fact that I am fluent in over six million forms\n" +
" of communication, I am unable to comprehend your request. Please specify\n" +
" the type of task that you wish to add Master!");
Copy link
Copy Markdown

@zikunz zikunz Sep 14, 2021

Choose a reason for hiding this comment

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

Really good usage of constants! Perhaps consider extracting them out to another class called Messages?


private static Task[] commands = new Task[SIZE];

// sendCommand() is a method used to allow the user to send his/her commands to C3PO
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Really great comment which follows "Explain WHAT and WHY, not HOW"!

From this week onwards, you could make it even better by adding JavaDoc comments for non-private classes / methods and non-trivial private methods.

private static void sendCommand() {
String line;
Scanner in = new Scanner(System.in);
while (byeFlag != 1) {
try {
System.out.println("____________________________________________________________\n");
System.out.print("Type something: ");
line = in.nextLine();
System.out.println("____________________________________________________________\n");
checkCommand(line);
} catch (DukeException e) {

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

According to https://nus-cs2113-ay2122s1.github.io/website/se-book-adapted/chapters/codeQuality.html#avoid-empty-catch-blocks, perhaps a comment can be written here which explains why the catch block is left empty.

}
}

// checkCommand() is a method that allows us to determine when the user says bye.
private static void checkCommand(String line) throws DukeException {
String[] input = line.split(" ");
if (line.equals("bye")) {
byeFlag = 1;
} else if (line.equals("list")) {
if (positionCheck == 0) {
throw new DukeException(EMPTY);
} else {
printList();
}
} else if (line.equals("done")) {
throw new DukeException(UNSPECIFIED_DONE);
} else if (input[0].equals("done")) {
if (positionCheck<=0) {
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, same as line 52, put an empty space before and after "<=" (i.e., positionCheck <= 0)? Other parts of the code such as line 85 seem to have similar potential issues.

throw new DukeException(EMPTY);
} else if ((Integer.parseInt(input[1]) > positionCheck ) || (Integer.parseInt(input[1]) <= 0)) {
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 there is an additional empty space after positionCheck here? It also seems to appear in other parts of the code such as line 86.

throw new DukeException(INVALID);
} else {
markDone(Integer.parseInt(input[1])-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.

According to https://nus-cs2113-ay2122s1.github.io/website/se-book-adapted/chapters/codeQuality.html#avoid-magic-numbers, perhaps you could spend some time trying to avoid magic numbers (there are also found elsewhere such as line 83) to further improve readability?

}
} else if (positionCheck >= SIZE) {
throw new DukeException(EXCEEDED);
} else {
checkTypeOfTask(line);
}
}

public static void sayBye() {
System.out.println("Goodbye master! May the force be with you!\n");
System.out.println("____________________________________________________________\n");
}
Copy link
Copy Markdown

@zikunz zikunz Sep 14, 2021

Choose a reason for hiding this comment

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

I like how you create a helper print function here! Perhaps you could also include these final strings (also found in other parts of the code such as line 93) in a new Message class later on?


public static void addDeadline(String[] input, int length) throws DukeException {
String description;
String by;
for (int i = 1 ; i < length ; i++) {
if ((input[i].equals("/by")) && (i != 1) && (i != (length-1))) {
description = input[1];
by = input[i+1];
for (int j = 2 ; j < i ; j++) {
description += (" " + input[j]);
}
for (int k = i+2 ; k < length ; k++) {
by += (" " + input[k]);
}
commands[positionCheck] = new Deadline(description,by);
System.out.println("Added to Galactic database:" );
System.out.println(commands[positionCheck]);
positionCheck += 1;
return;
}
}
throw new DukeException(DEADLINE_ERROR);
}

public static void addEvent(String[] input, int length) 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.

Perhaps you could leave a space here before { for layout consistency? This applies to other similar parts of your code (e.g., line 125).

String description;
String at;
for (int i = 1 ; i < length ; i++) {
if ((input[i].equals("/at")) && (i != 1) && (i != (length-1))) {
description = input[1];
at = input[i+1];
for (int j = 2 ; j < i ; j++) {
description += (" " + input[j]);
}
for (int k = i+2 ; k < length ; k++) {
at += (" " + input[k]);
}
commands[positionCheck] = new Event(description,at);
System.out.println("Added to Galactic database:" );
System.out.println(commands[positionCheck]);
positionCheck += 1;
return;
}
}
throw new DukeException(EVENT_ERROR);
}

public static void addTodo (String[] input, int length) 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.

Clean and clear naming of methods! But it looks like there is an additional empty space after addTodo here.

if (length == 1) {
throw new DukeException(TODO_ERROR);
} else {
String description = input[1];
for (int i = 2 ; i < length ; i++) {
description += (" " + input[i]);
}
commands[positionCheck] = new Todo(description);
System.out.println("Added to Galactic database:" );
System.out.println(commands[positionCheck]);
positionCheck += 1;
}
}

public static void checkTypeOfTask(String line) throws DukeException {
String[] input = line.split(" ");
int length = input.length;
if (input[0].toLowerCase().equals("deadline")) {
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 consider spliting the complicated expression in mutiple steps (e.g., define and give a name for what is input[0] and input[0].toLowerCase()).

addDeadline(input,length);
} else if (input[0].toLowerCase().equals("event")) {
addEvent(input,length);
} else if (input[0].toLowerCase().equals("todo")) {
addTodo(input,length);
} else {
throw new DukeException(UNSPECIFIED_TASK);
}
}

private static void printList() {
System.out.println("Accessing archives...");
for (int i = 0; i < positionCheck; i++) {
System.out.println((i+1) + ". " + commands[i]);
}
}

private static void markDone(int doneTaskNumber) {
commands[doneTaskNumber].markAsDone();
System.out.println("The following task has been marked as done Master!");
System.out.println((doneTaskNumber+1) + ". " + commands[doneTaskNumber]);
}

public static void greetUser() {
String logo = " /~\\\n"
+ " |oo )\n"
+ " _\\=/_\n"
+ " / \\\n"
+ " //|/.\\|\\\\\n"
+ " || \\_/ ||\n"
+ " || |\\ /| ||\n"
+ " # \\_ _/ #\n"
+ " | | |\n"
+ " | | |\n"
+ " []|[]\n"
+ " | | |\n"
+ " /_]_[_\\\n";
System.out.println("____________________________________________________________\n");
System.out.println("Hello! I am C3P0! Human-cyborg relations! \n" + " \n" + logo);
System.out.println("What can I do for you my master?\n");
}

public static void main (String[] args) throws DukeException {
greetUser();
sendCommand();
sayBye();
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All statements are at the same level of abstraction, great! You have followed of Single Level of Abstraction Principle (SLAP) very well!

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

public class DukeException extends Exception {
public DukeException(String errorMessage){
super(errorMessage);
System.out.println(errorMessage);
}
}
Comment on lines +3 to +16
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great use of super, with this overwriting of error messages are done easily

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

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][" + getStatusIcon() + "] " + super.toString() + " (at: " + at + ")";
}
}
23 changes: 23 additions & 0 deletions src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package duke;

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

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

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

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

public String toString() {
return description;
}
}
13 changes: 13 additions & 0 deletions src/main/java/duke/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke;

public class Todo extends Task{

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

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

Hello! I am C3P0! Human-cyborg relations!

/~\
|oo )
_\=/_
/ \
//|/.\|\\
|| \_/ ||
|| |\ /| ||
# \_ _/ #
| | |
| | |
[]|[]
| | |
/_]_[_\

What can I do for you my master?

____________________________________________________________

Type something: ____________________________________________________________

Added to Galactic database:
[T][ ] go the gym
____________________________________________________________

Type something: ____________________________________________________________

Added to Galactic database:
[D][ ] submit assignment (by: 12)
____________________________________________________________

Type something: ____________________________________________________________

Goodbye master! May the force be with you!

____________________________________________________________

3 changes: 3 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
todo go the gym
deadline submit assignment /by 12
bye
4 changes: 3 additions & 1 deletion text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ REM compile the code into the bin folder
javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java
IF ERRORLEVEL 1 (
echo ********** BUILD FAILURE **********
pause
exit /b 1
)
REM no error here, errorlevel == 0

REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ..\bin Duke < input.txt > ACTUAL.TXT
java -classpath ..\bin duke.Duke < input.txt > ACTUAL.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT
pause