Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
6b8c2f2
Level1. Greet,Echo,Exit
SimJM Jan 20, 2022
778d1e0
add Action class
SimJM Jan 20, 2022
8009280
Level-2: added readBook(), returnBook()
SimJM Jan 20, 2022
8fa8a55
Level-3: Mark as Done. Added Task class
SimJM Jan 20, 2022
3357573
Level-4: todo, deadline, event
SimJM Jan 20, 2022
f2fabf0
A-TextUiTesting
SimJM Jan 20, 2022
a210a0f
Level-5 Handle Errors
SimJM Jan 20, 2022
8a7ee50
Level-6 delete
SimJM Jan 20, 2022
a51d3f3
A-Enums
SimJM Jan 20, 2022
5b8561d
refactor code (add TaskBank, Parser, User class)
SimJM Feb 6, 2022
3d7329e
Level-7 Save
SimJM Feb 6, 2022
5dcf7b0
minor edits
SimJM Feb 6, 2022
6b65fea
incomplete branch
SimJM Feb 8, 2022
4ab3dac
Add LocalDate and format date
SimJM Feb 15, 2022
832f67b
implement date format
SimJM Feb 15, 2022
507c6a3
Revert "implement date format"
SimJM Feb 15, 2022
7f7f081
Revert "Revert "implement date format""
SimJM Feb 15, 2022
b8d7f64
Level 8 - add date format
SimJM Feb 15, 2022
70d14c8
A-MoreOOP - Ui class
SimJM Feb 15, 2022
8695409
A-Packages: organize classes into duke package
SimJM Feb 15, 2022
4ac330a
Add JUnit tests
SimJM Feb 15, 2022
26bba93
Package the App as a JAR file
SimJM Feb 16, 2022
95823e5
A-JavaDoc - Add JavaDoc comments
SimJM Feb 16, 2022
81232fa
A-CodingStandard - Tweak the code to comply with a coding standard
SimJM Feb 16, 2022
726b27f
Merge branch 'branch-Level-8' into branch-A-CodingStandard
SimJM Feb 16, 2022
52b6b7c
Level-9 Find - give users a way to find a task by searching for a key…
SimJM Feb 16, 2022
dee52c7
Merge branch 'branch-A-CodingStandard'
SimJM Feb 16, 2022
e1ccf9d
Merge branch 'branch-Level-9'
SimJM Feb 16, 2022
3c83a87
Merge commit 'd8398594b7bc43da5eb865321c5a50cec4b3923d'
SimJM Feb 16, 2022
a018811
A-CheckStyle - edit coding style violations
SimJM Feb 16, 2022
fe06e8f
Level-10 GUI - add a GUI to Duke. Use the JavaFX technology to implem…
SimJM Feb 17, 2022
b3a9390
A-Varargs - not applicable
SimJM Feb 17, 2022
53330a6
Add assertion
SimJM Feb 17, 2022
8cfee6f
Improve code quality
SimJM Feb 17, 2022
4aaed72
Merge branch 'branch-A-CodeQuality'
SimJM Feb 17, 2022
25c776d
C-update - easily edit description of the Task
SimJM Feb 17, 2022
807bab5
Improve the GUI
SimJM Feb 18, 2022
ba460f1
Improve GUI
SimJM Feb 18, 2022
ae805b1
Edit on code quality
SimJM Feb 18, 2022
70a7cf8
Add update into help function
SimJM Feb 18, 2022
b5a30d2
Merge branch 'master' into branch-C-update
SimJM Feb 18, 2022
6992122
Merge pull request #2 from SimJM/branch-C-update
SimJM Feb 18, 2022
9e89a02
tidy up code
SimJM Feb 18, 2022
f56ff47
Set theme jekyll-theme-merlot
SimJM Feb 18, 2022
9181b89
upload Ui.png
SimJM Feb 18, 2022
a914019
Merge branch 'master' of https://github.com/SimJM/ip
SimJM Feb 18, 2022
046d881
Update README.md
SimJM Mar 12, 2022
000f5a1
Update README.md
SimJM Mar 12, 2022
8ed816b
Add exception handling in parser
SimJM Mar 20, 2022
b7ec4fe
Add exception handling
SimJM Mar 20, 2022
09593f8
Add output
SimJM Mar 20, 2022
98566a3
Update README
SimJM Mar 20, 2022
d232468
Update README.md
SimJM Mar 20, 2022
4352935
Update README.md
SimJM Mar 20, 2022
f3191a8
Update README.md
SimJM Mar 20, 2022
3bc0613
Update README.md
SimJM Mar 20, 2022
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
3 changes: 3 additions & 0 deletions src/main/java/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main/java/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/main/java/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main/java/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

public class Action {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks clean!


Action() {}

void greet() {
String greet = "Hello! I'm JiaMing\nWhat can I do for you?\n";
System.out.println(greet);
}

void echo(String phrase) {
System.out.println(phrase);
}

void bye() {
String bye = "Bye. Hope to see you again soon!\n";
System.out.println(bye);
}

void showList(ArrayList<Task> arrlst) {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < arrlst.size(); i++) {
String output = String.format("%d.[%s][%s]%s\n", i + 1, arrlst.get(i).sym,
arrlst.get(i).getStatusIcon(), arrlst.get(i).description);
System.out.println(output);
}
}
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 use a javadocs documentation.


@Override
public String toString() {
return "this is an Action (Parent)";
}

}
20 changes: 20 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Deadline extends Task {
protected final String sym = "D";
protected String day;

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

@Override
String getSym() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would opt for a more intuitive name rather than sym.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would opt for a more intuitive name rather than sym.

Maybe you can change it to a more descriptive name such as symbol?

return this.sym;
}

@Override
public String toString() {
return String.format("[%s][%s]%s (by:%s)", sym, super.getStatusIcon(), super.description, this.day);
}

}
109 changes: 103 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,107 @@
// enums not applicable

import java.util.Scanner;
import java.util.ArrayList;

public class Duke {
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);
ArrayList<Task> arrlst = new ArrayList<>();
String DASH = "____________________________________________________________";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works too, but UI can be separated into a class for cleanliess

Action act = new Action();

act.greet();

while (sc.hasNext()) {
String phrase = sc.nextLine();
System.out.println(DASH);

if (phrase.equals("list")) {
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 can consider using a switch statement instead?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The code here is pretty long, but you will get to break it down later as you progress with the iP. Consider doing the printing in separate functions and get your switch statement to invoke those print functions instead.

act.showList(arrlst);
} else if (phrase.equals("bye")) {
act.bye();
System.out.println(DASH);
break;
} else {
String[] arrWords = phrase.split(" ");
try { // mark or unmark
int num = Integer.valueOf(arrWords[1]);
if (arrWords[0].equals("mark")) {
arrlst.get(num - 1).markAsDone();
} else if (arrWords[0].equals("unmark")) {
arrlst.get(num - 1).markAsNotDone();
} else if (arrWords[0].equals("delete")) {
System.out.println("Noted. I've removed this task:");
Task t = arrlst.get(num - 1);
String output = String.format("[%s][%s]%s", t.getSym(), t.getStatusIcon(), t.description);
System.out.println(output);
System.out.println("Now you have 4 tasks in the list.");
arrlst.remove(num - 1);
} else {
System.out.println("siao eh");
}
} catch (NumberFormatException nfe) { // add new task like read book, return book
String gotIt = "Got it. I've added this task:";

if (arrWords[0].equals("todo")) {
String remainingWords = "";
for (int i = 1; i < arrWords.length; i++) {
remainingWords = remainingWords + " " + arrWords[i];
}
Todo t = new Todo(remainingWords);
arrlst.add(new Task(t.description, t.sym));
System.out.println(gotIt);
System.out.println(t);
String noOfTask = String.format("Now you have %d tasks in the list.", arrlst.size());
System.out.println(noOfTask);
} else if (arrWords[0].equals("deadline")) {
String remainingWords = "";
String dLine = "";
for (int i = 1; i < arrWords.length; i++) {
if (arrWords[i].equals("/by")) {
for (int j = i + 1; j < arrWords.length; j++) {
dLine = dLine + " " + arrWords[j];
}
break;
} else {
remainingWords = remainingWords + " " + arrWords[i];
}
}
Deadline t = new Deadline(remainingWords, dLine);
arrlst.add(new Task(t.description, t.sym));
System.out.println(gotIt);
System.out.println(t);
String noOfTask = String.format("Now you have %d tasks in the list.", arrlst.size());
System.out.println(noOfTask);
} else if (arrWords[0].equals("event")) {
String remainingWords = "";
String dayAndTime = "";
for (int i = 1; i < arrWords.length; i++) {
if (arrWords[i].equals("/at")) {
for (int j = i + 1; j < arrWords.length; j++) {
dayAndTime = dayAndTime + " " + arrWords[j];
}
break;
} else {
remainingWords = remainingWords + " " + arrWords[i];
}
}
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 use comments in places like these to explain what the code is doing (i.e. splitting up the user input) as it may not be apparent on first sight.

Event t = new Event(remainingWords, dayAndTime);
arrlst.add(new Task(t.description, t.sym));
System.out.println(gotIt);
System.out.println(t);
String noOfTask = String.format("Now you have %d tasks in the list.", arrlst.size());
System.out.println(noOfTask);
}
} catch (ArrayIndexOutOfBoundsException aioobe) { // echo
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 can consider changing the parameter name to just e instead.

if (arrWords[0].equals("todo")) {
System.out.println("OOPS!!! The description of a todo cannot be empty.");
} else {
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}
}
System.out.println(DASH);
}
}
}
21 changes: 21 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Event extends Task {
protected final String sym = "E";
private String dayAndTime;

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

@Override
String getSym() {
return this.sym;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

May I check what is the purpose of this override? Same with deadline and todo classes. Seems redundant as the getSym() in Task is the same.


@Override
public String toString() {
return String.format("[%s][%s]%s (at:%s)", sym, super.getStatusIcon(), super.description, this.dayAndTime);
}


}
45 changes: 45 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
public class 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.

It is possible to change Task to an abstract class?

protected String description;
Copy link
Copy Markdown

@KwanHW KwanHW Feb 3, 2022

Choose a reason for hiding this comment

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

While protected may appear sufficient, these attributes can still be accessible by other functions once you start putting them into packages. Consider changing your attributes to private

protected boolean isDone;
protected String sym;

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

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

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

public void markAsDone() {
this.isDone = true;
System.out.println("Nice! I've marked this task as done:");
String output = String.format(" [%s][%s] %s", this.sym, this.getStatusIcon(), this.description);
System.out.println(output);
}

public void markAsNotDone() {
this.isDone = false;
System.out.println("OK, I've marked this task as not done yet:");
String output = String.format(" [%s] %s", this.getStatusIcon(), this.description);
System.out.println(output);
}

String getSym() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing public keyword at function signature

return this.sym;
}

@Override
public String toString() {
return String.format("added: %s", 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.

I think you should change your toString() method to print out the sym, isDone and description instead of this message. This can reduce code duplication in your children classes as I observed that they are using attributes in Task to form the string.

}
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 use some javadocs documentation as Task is the parent class.


}
18 changes: 18 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Todo extends Task {
protected final String sym = "T";

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

@Override
String getSym() {
return this.sym;
}

@Override
public String toString() {
return String.format("[%s][%s]%s", sym, super.getStatusIcon(), super.description);
}

}
3 changes: 3 additions & 0 deletions src/main/java/out/production/main/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main/java/out/production/main/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/main/java/out/production/main/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main/java/out/production/main/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added src/main/java/out/production/main/Duke.class
Binary file not shown.
14 changes: 8 additions & 6 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
Hello! I'm JiaMing
What can I do for you?

____________________________________________________________
Got it. I've added this task:
[T][ ] borrow book
Now you have 1 tasks in the list.
____________________________________________________________

1 change: 1 addition & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
todo borrow book