Skip to content
Open

iP #188

Show file tree
Hide file tree
Changes from 8 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
15 changes: 15 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

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 + ")";
}
}
190 changes: 184 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,188 @@
import java.util.Locale;
import java.util.Scanner;

public class Duke {

private static int byeFlag = 0;
private static int positionCheck = 0;
private static Task[] commands = new Task[100];

// sendCommands() is a method used to allow the user to send his/her commands to C3PO
private static void sendCommands() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could be changed to sayCommand as there is only 1 command

String line;
Scanner in = new Scanner(System.in);
while (byeFlag != 1) {
System.out.println("____________________________________________________________\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion:
Make a variable for printing underscore.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion:
Make a variable for printing underscore.

System.out.print("Type something: ");
line = in.nextLine();
System.out.println("____________________________________________________________\n");
checkCommands(line);
}
}

// checkCommands() is a method that allows us to determine when the user says bye.
private static void checkCommands(String line) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similarly for this could be checkCommand

String[] input = line.split(" ");
if (line.equals("bye")) {
byeFlag = 1;
} else if (line.equals("list")) {
if (positionCheck == 0) {
sayEmpty();
} else {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion:
Avoid deep nesting.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: Avoid deep nesting.

printList();
}
} else if (line.equals("done")) {
sayNotSpecified();
} else if (input[0].equals("done")) {
if ((Integer.parseInt(input[1]) > positionCheck ) || (Integer.parseInt(input[1]) <= 0)) {
sayInvalidNumber();
} else if (positionCheck<=0) {
sayEmpty();
} else {
markDone(Integer.parseInt(input[1])-1);
}
} else if (positionCheck >= 100) {
sayExceededCapacity();
} else {
checkTypeOfTask(line);
}
}

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

public static void sayEmpty() {
System.out.println("There is no data in your list master!");
}

public static void sayExceededCapacity() {
System.out.println("Oh dear me! We have exceeded my system's maximum capacity!");
}

public static void sayNotSpecified() {
System.out.println("Oh no master, I am not quite sure which task you would like me to mark as done");
}

public static void sayInvalidNumber() {
System.out.println("Please type in a valid number master! Type \"list\" to check the index number of your list data");
}

public static void addDeadline(String[] input, int length) {
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;
}
}
System.out.println("Sorry Master! I don't think you have properly keyed in the parameters. Please enter the task, followed by \"/by\",\n" +
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could be split into 2 println statements to improve readability

"followed by the due date to specify the deadline Master!");
}

public static void addEvent(String[] input, int length) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try to use single level abstraction.

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;
}
}
System.out.println("Sorry Master! I don't think you have properly keyed in the parameters. \n" +
"Please enter the event, followed by \"/at\", followed by the event duration to specify \n" +
"the timing of the event Master!");
}

public static void addTodo (String[] input, int length) {
if (length == 1) {
System.out.println("Sorry Master! I don't think you have properly keyed in the parameters.\n" +
" Please enter the task you wish to add to your Todo list Master!");
} 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) {
String[] input = line.split(" ");
int length = input.length;
if (input[0].toLowerCase().equals("deadline")) {
addDeadline(input,length);
} else if (input[0].toLowerCase().equals("event")) {
addEvent(input,length);
} else if (input[0].toLowerCase().equals("todo")) {
addTodo(input,length);
} else {
System.out.println("Sorry Master! Please specify the type of task that you wish to add as well!");
}
}

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) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
greetUser();
sendCommands();
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.

Overall, good naming conventions used 💯

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{

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 + ")";
}
}
21 changes: 21 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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;
}
}
11 changes: 11 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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
2 changes: 2 additions & 0 deletions text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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
Expand All @@ -19,3 +20,4 @@ java -classpath ..\bin Duke < input.txt > ACTUAL.TXT

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