Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kuek Yan Ling] iP #248

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3b19ba1
Add Gradle support
May 24, 2020
a75fcee
build.gradle: Update version to 8.29
Aug 29, 2020
77ee7e3
Complete Level-1: Greet, Echo, Exit
yanlingkuek Jan 20, 2021
27ef333
Complete Level-2: Add, List
yanlingkuek Jan 20, 2021
cecd097
Complete Level-3: Mark as Done
yanlingkuek Jan 20, 2021
cd80752
Complete Level-4: ToDo, Event, Deadline
yanlingkuek Jan 20, 2021
6c6269a
Complete A-TextUiTesting: Automated Text UI Testing
yanlingkuek Jan 20, 2021
96e15e5
Complete Level-4: ToDo, Events, Deadlines (updated)
yanlingkuek Jan 20, 2021
76ba712
Completed A-TextUiTesting: Automated Text UI Testing (updated)
yanlingkuek Jan 20, 2021
6597495
Complete A-TextUiTesting: Automated Text UI Testing (updated new)
yanlingkuek Jan 21, 2021
cfcf682
Complete Level-5: Handle Errors
yanlingkuek Jan 21, 2021
e59f9f4
Complete Level-6: Delete
yanlingkuek Jan 21, 2021
5fcc0a6
Reorganise Level 1-6
yanlingkuek Feb 5, 2021
9a16853
Correct style issues
yanlingkuek Feb 5, 2021
89416ab
Add JavaDoc
yanlingkuek Feb 5, 2021
dbb3271
Add saving feature (Complete Level 7)
yanlingkuek Feb 5, 2021
e60caaa
Add features to read date and time (Complete Level 8)
yanlingkuek Feb 5, 2021
0b06a57
Add JavaDoc and user instructions
yanlingkuek Feb 5, 2021
b2ed9a0
Merge branch 'branch-Level-8'
yanlingkuek Feb 5, 2021
628dd4f
Add classes Ui, Storage, Parser, Command, AddCommand, DeleteCommand, …
yanlingkuek Feb 5, 2021
e0eb53a
Divide classes into packages
yanlingkuek Feb 6, 2021
96fe041
Add JUnit tests (Complete A-JUnit)
yanlingkuek Feb 6, 2021
3860020
Add more JavaDocs (Complete A-JavaDoc)
yanlingkuek Feb 7, 2021
1213091
Tweak code to comply with coding standard (Complete A-CodingStandard)
yanlingkuek Feb 7, 2021
47369e7
Fix duke.txt file reading issues
yanlingkuek Feb 7, 2021
38eb8b5
Add new command: find (Complete Level-9)
yanlingkuek Feb 7, 2021
7390e40
Merge branch 'branch-A-CodingStandard'
yanlingkuek Feb 7, 2021
cd44e0f
Merge branch 'branch-Level-9'
yanlingkuek Feb 7, 2021
573bb90
Merge branch 'add-gradle-support' of https://github.com/yanlingkuek/ip
yanlingkuek Feb 10, 2021
177e775
Use checkstyle (Complete A-CheckStyle)
yanlingkuek Feb 10, 2021
17ca5e2
Add GUI (Complete Level-10)
yanlingkuek Feb 10, 2021
a70beff
Fix issue with done command
yanlingkuek Feb 19, 2021
699f6cc
Add assertions (Complete A-Assertions)
yanlingkuek Feb 19, 2021
1e9c795
Improve code quality (Complete A-CodeQuality)
yanlingkuek Feb 19, 2021
ff944f3
Add feature to check if the new task to be added already exists in th…
yanlingkuek Feb 19, 2021
189ae2f
Merge pull request #2 from yanlingkuek/branch-A-Assertions
yanlingkuek Feb 19, 2021
d7976a0
Merge branch 'master' of https://github.com/yanlingkuek/ip into branc…
yanlingkuek Feb 19, 2021
5c8e8f0
Merge branch 'branch-A-CodeQuality'
yanlingkuek Feb 19, 2021
51a933e
Merge branch 'branch-BCD-Extension'
yanlingkuek Feb 19, 2021
2b78ce8
Change exception message
yanlingkuek Feb 19, 2021
9b21785
Add screenshot of UI and window title.
yanlingkuek Feb 19, 2021
67d669d
Update README file.
yanlingkuek Feb 19, 2021
fc9f60a
Add user guide and update README.
yanlingkuek Feb 19, 2021
ec49759
Change main class name.
yanlingkuek Feb 19, 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
15 changes: 15 additions & 0 deletions src/main/java/DeadlineTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class DeadlineTask extends Task {

Choose a reason for hiding this comment

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

Maybe you can consider putting classes into packages.


protected String deadline;

public DeadlineTask(String description, String deadlline) {

Choose a reason for hiding this comment

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

Perhaps there is a typo for a variable name for deadline rather than deadlline.

Choose a reason for hiding this comment

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

Perhaps there can be Javadoc comments to tell readers how this method works.

super(description);
this.deadline = deadlline;
}

@Override
public String toString() {
return "[D]" + "[" + getStatusIcon() + "] " + this.description
+ " (by: " + this.deadline + ")";
}
}
191 changes: 185 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,189 @@
import java.util.*;

Choose a reason for hiding this comment

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

Perhaps imported classes should be listed explicitly? (:

Choose a reason for hiding this comment

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

importing tasks individually can be clearer.


public class Duke {

static void level1() {

Choose a reason for hiding this comment

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

Perhaps having a method name that briefly describes what it does would be clearer.

Choose a reason for hiding this comment

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

Perhaps it would be clearer if this method name starts with a verb?

System.out.println("Hello! I'm Duke\n" + "What can I do for you?");

Scanner sc = new Scanner(System.in);
String input = sc.nextLine();

while (!input.equals("bye")) {
System.out.println(input);
input = sc.nextLine();
}

System.out.println("Bye. Hope to see you again soon!");
}


static void level2() {

Choose a reason for hiding this comment

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

Perhaps the method names could be more descriptive? In verb form? (:

System.out.println("Hello! I'm Duke\n" + "What can I do for you?");

Scanner sc = new Scanner(System.in);
String input = sc.nextLine();

List<String> lst = new ArrayList<>();

Choose a reason for hiding this comment

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

Perhaps the parameter name can be something like commands? lst may sound a bit unclear to readers.


while (!input.equals("bye")) {
if (!input.equals("list")) {
lst.add(input);
System.out.println("added: " + input);
} else {
for (int i = 1; i <= lst.size(); i++) {
System.out.println(i + ". " + lst.get(i-1));

Choose a reason for hiding this comment

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

Perhaps there should be whitespace on the left and right of the "-" sign? (:
list.get(i - 1);

Choose a reason for hiding this comment

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

Not sure if I liked that the - does not have whitespace before and after it.

}
}
input = sc.nextLine();
}

System.out.println("Bye. Hope to see you again soon!");

}


Choose a reason for hiding this comment

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

Perhaps more javadoc comments for the methods? (:

static void level3() {

Choose a reason for hiding this comment

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

I would personally an access modifier for my method to show whether it can be used outside the package or class.

List<Task> lst = new ArrayList<>();

Choose a reason for hiding this comment

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

Perhaps instead of lst, using tasks could be clearer to know what the list contains.

lst.add(new Task("read book"));
lst.add(new Task("return book"));
lst.add(new Task("buy bread"));
lst.get(0).markAsDone();

Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
String[] inputArray = input.split(" ");

Choose a reason for hiding this comment

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

perhaps rather than inputArray, you can have a plural form of the input to show that it has multiple parts.


while (true) {
if (input.equals("list")) {
System.out.println("Here are the tasks in your list:");

for (int i = 1; i <= lst.size(); i++) {
System.out.println(i + "." + lst.get(i - 1));
}
} else if (inputArray[0].equals("done")) {
System.out.println("Nice! I've marked this task as done:");
lst.get(Integer.parseInt(inputArray[1]) - 1).markAsDone();
System.out.println(" " + lst.get(Integer.parseInt(inputArray[1]) - 1));
}

input = sc.nextLine();
inputArray = input.split(" ");
}
}

static void level4() throws DukeException {
List<Task> lst = new ArrayList<>();
lst.add(new ToDoTask("read book"));
lst.add(new DeadlineTask("return book", "June 6th"));
lst.add(new EventTask("project meeting", "Aug 6th 2-4pm"));
lst.add(new ToDoTask("join sports club"));
lst.get(0).markAsDone();
lst.get(3).markAsDone();

Scanner sc = new Scanner(System.in);
String input;
String[] inputArray;

while (sc.hasNextLine()) {
input = sc.nextLine();
inputArray = input.split(" ");
if (inputArray[0].equals("list")) {
System.out.println("Here are the tasks in your list:");
for (int i = 1; i <= lst.size(); i++) {
System.out.println(i + "." + lst.get(i - 1));
}
} else if (inputArray[0].equals("todo") || inputArray[0].equals("deadline") || inputArray[0].equals("event")) { //adding a task
Task task = new Task("");
String[] inputArr1;

Choose a reason for hiding this comment

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

perhaps extracting all the code that deals with different types of tasks could make your code clearer.

String[] inputArr2;
if (inputArray[0].equals("todo")) {
if (inputArray.length == 1) {
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty.");
}
inputArr1 = input.split("todo ");
task = new ToDoTask(inputArr1[1]);
} else if (inputArray[0].equals("deadline")) {
if (inputArray.length == 1) {
throw new DukeException("☹ OOPS!!! The description of a deadline cannot be empty.");
}
inputArr1 = input.split("deadline ");
inputArr2 = inputArr1[1].split(" /by ");
task = new DeadlineTask(inputArr2[0], inputArr2[1]);
} else if (inputArray[0].equals("event")) {
if (inputArray.length == 1) {
throw new DukeException("☹ OOPS!!! The description of a deadline cannot be empty.");
}
inputArr1 = input.split("event ");
inputArr2 = inputArr1[1].split(" /at ");
task = new EventTask(inputArr2[0], inputArr2[1]);
}
lst.add(task);
System.out.println("Got it. I've added this task: ");
System.out.println(" " + task);
System.out.println("Now you have " + lst.size() + " tasks in the list.");
} else {
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}

}


}


static void level6() throws DukeException {
List<Task> lst = new ArrayList<>();
lst.add(new ToDoTask("read book"));
lst.add(new DeadlineTask("return book", "June 6th"));
lst.add(new EventTask("project meeting", "Aug 6th 2-4pm"));
lst.add(new ToDoTask("join sports club"));
lst.add(new ToDoTask("borrow book"));
lst.get(0).markAsDone();
lst.get(1).markAsDone();
lst.get(3).markAsDone();

Scanner sc = new Scanner(System.in);
String input;
String[] inputArray;

while (sc.hasNextLine()) {
input = sc.nextLine();
inputArray = input.split(" ");
if (inputArray[0].equals("list")) {
System.out.println("Here are the tasks in your list:");
for (int i = 1; i <= lst.size(); i++) {
System.out.println(i + "." + lst.get(i - 1));
}
} else if (inputArray[0].equals("delete")) { //deleting a task
if (inputArray.length == 1) {
throw new DukeException("☹ OOPS!!! The task number has not been specified.");
} else if (Integer.parseInt(inputArray[1]) > lst.size()) {
throw new DukeException("☹ OOPS!!! This task number does not exist.");
}

System.out.println("Noted. I've removed this task:");
System.out.println(" " + lst.get(Integer.parseInt(inputArray[1]) - 1));
lst.remove(Integer.parseInt(inputArray[1]) - 1);
System.out.println("Now you have " + lst.size() + " tasks in the list.");
}
}
}


public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

try {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

level6();
} catch (DukeException e) {
System.out.println(e);
}

}
}
7 changes: 7 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class DukeException extends Exception {

DukeException(String msg) {
super(msg);
}

}
15 changes: 15 additions & 0 deletions src/main/java/EventTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class EventTask extends Task {

protected String eventDate;

public EventTask(String description, String eventDate) {
super(description);
this.eventDate = eventDate;
}

@Override
public String toString() {
return "[E]" + "[" + getStatusIcon() + "] " + this.description
+ " (at: " + this.eventDate + ")";
}
}
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;

Choose a reason for hiding this comment

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

I like the name of this boolean, clearly tells me what it does.


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

public String getStatusIcon() {
return (isDone ? "X" : " "); //return tick or X symbols
}

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

public String toString() {
return "[" + getStatusIcon() + "] " + this.description;
}
}
3 changes: 3 additions & 0 deletions src/main/java/TaskTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public enum TaskTypes {
TODO, DEADLINE, EVENT;
}
11 changes: 11 additions & 0 deletions src/main/java/ToDoTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class ToDoTask extends Task {

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

@Override
public String toString() {
return "[T]" + "[" + getStatusIcon() + "] " + this.description;
}
}
15 changes: 15 additions & 0 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ Hello from
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Got it. I've added this task:
[T][ ] borrow book
Now you have 5 tasks in the list.
Here are the tasks in your list:
1.[T][X] read book
2.[D][ ] return book (by: June 6th)
3.[E][ ] project meeting (at: Aug 6th 2-4pm)
4.[T][X] join sports club
5.[T][ ] borrow book
Got it. I've added this task:
[D][ ] return book (by: Sunday)
Now you have 6 tasks in the list.
Got it. I've added this task:
[E][ ] project meeting (at: Mon 2-4pm)
Now you have 7 tasks in the list.
4 changes: 4 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
todo borrow book
list
deadline return book /by Sunday
event project meeting /at Mon 2-4pm