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

[Qiu Qianhui] iP #376

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
2abf484
Add Increment Level-1
QQH0828 Jan 30, 2023
6e6c66f
Add Increment Level-2
QQH0828 Jan 30, 2023
8e390d2
Add Increment Level-3 with a new class Task
QQH0828 Jan 30, 2023
63deb9f
Add Increments Level-4
QQH0828 Jan 31, 2023
638fe5e
Add Increments for Automated Text UI Testing
QQH0828 Jan 31, 2023
fea77b0
Add Increment Level-5
QQH0828 Jan 31, 2023
a6d87e4
Add Increment Level-6
QQH0828 Jan 31, 2023
a57249e
Add Increment Level -7 as parallel branche with Save method
QQH0828 Feb 7, 2023
1bc3b13
Merge branch 'branch-Level-7'
QQH0828 Feb 7, 2023
3d7c8f3
Merge branch 'branch-Level-8'
QQH0828 Feb 7, 2023
f308ef4
Add Increments as parallel branche-Level-8 with Dates and Times
QQH0828 Feb 7, 2023
eaeedb9
Add Increments as parallel branch-Level-7 with Save method
QQH0828 Feb 7, 2023
db837df
Merge branch 'branch-Level-7'
QQH0828 Feb 7, 2023
1e9262f
Merge branch 'branch-Level-8'
QQH0828 Feb 7, 2023
e1c0c5e
Solve merge conflict branch-Level-8
QQH0828 Feb 7, 2023
858927b
Merge remote-tracking branch 'origin/master'
QQH0828 Feb 7, 2023
c88a915
Merge branch 'add-gradle-support' of https://github.com/nus-cs2103-AY…
QQH0828 Feb 7, 2023
817bcee
Add Increment: A-MoreOOP
QQH0828 Feb 12, 2023
6a8cd60
Add Increment: A-Packages
QQH0828 Feb 12, 2023
1a75274
Add Increment: A-Gradle
QQH0828 Feb 12, 2023
f896222
Add Increment: A-JUnit
QQH0828 Feb 13, 2023
5e84399
Add Increments as parallel branches: A-JavaDoc
QQH0828 Feb 13, 2023
06a30bd
Add Increments as parallel branches: Level-9
QQH0828 Feb 13, 2023
bc80cb8
Add Increments as parallel branches: Level-9
QQH0828 Feb 13, 2023
2afc403
Add Increments as parallel branches: A-CodingStandard
QQH0828 Feb 13, 2023
b05471e
Merge branch 'branch-A-JavaDoc'
QQH0828 Feb 13, 2023
0f3fe17
Merge branch 'branch-Level-9'
QQH0828 Feb 13, 2023
a7b2d76
Merge branch 'branch-A-CodingStandard'
QQH0828 Feb 13, 2023
895bae8
Add Increments as branches: A-CheckStyle
QQH0828 Feb 13, 2023
d3b4044
Delete unused classes
QQH0828 Feb 15, 2023
74bdb53
Add Increments as branches: Level-10
QQH0828 Feb 15, 2023
ff5718d
Merge branch 'branch-Level-10'
QQH0828 Feb 15, 2023
e9c03a4
Add assert statement in the TaskList class
QQH0828 Feb 15, 2023
6c72fb3
Modify the codes based on the code quality
QQH0828 Feb 15, 2023
bc2e9a6
Merge pull request #2 from QQH0828/branch-A-Assertions
QQH0828 Feb 15, 2023
3e7ebc9
Merge branch 'master' of https://github.com/QQH0828/ip
QQH0828 Feb 15, 2023
2c7366f
Merge pull request #3 from QQH0828/branch-A-CodeQuality
QQH0828 Feb 15, 2023
11b85c6
Merge branch 'master' of https://github.com/QQH0828/ip
QQH0828 Feb 15, 2023
da2cede
Merge branch 'master' into branch-A-Assertions
QQH0828 Feb 15, 2023
9e36d1c
Merge branch 'master' into branch-A-CodeQuality
QQH0828 Feb 15, 2023
4ef0415
Merge branch 'branch-A-Assertions'
QQH0828 Feb 15, 2023
4b65663
Merge branch 'branch-A-CodeQuality'
QQH0828 Feb 15, 2023
f7f30c0
Add Increment: A-CI
QQH0828 Feb 15, 2023
3a8547a
Add an extension: C-Help
QQH0828 Feb 16, 2023
786fd75
Merge branch 'branch-C-Help'
QQH0828 Feb 16, 2023
9e53f70
Fix CheckStyle errors
QQH0828 Feb 16, 2023
85a4776
Add a unique personality
QQH0828 Feb 17, 2023
6882f68
Resolve the command error
QQH0828 Feb 17, 2023
ac99812
Fix the import format order issues
QQH0828 Feb 17, 2023
3b97191
Fix import format in parser class
QQH0828 Feb 17, 2023
9ff9abb
Fix checkstyle error
QQH0828 Feb 17, 2023
26f91eb
Add java doc in ui class
QQH0828 Feb 17, 2023
832d46a
Fix checkstyle error of DeadlineTest and DateTimeTest classes
QQH0828 Feb 17, 2023
f7536e5
Fix the checkstyle error in the DateTimeTest class
QQH0828 Feb 17, 2023
abd962b
Set up a product website with a representative screenshot and user guide
QQH0828 Feb 17, 2023
769a11d
Add help command in the user guide
QQH0828 Feb 17, 2023
b5d8dc4
Finalize the features
QQH0828 Feb 17, 2023
8cd75f8
Fix no match tasks while using find command
QQH0828 Feb 17, 2023
a19d9e3
Fix some errors to make it more user friendly
QQH0828 Feb 17, 2023
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
13 changes: 13 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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]" + super.toString() + " (by: " + by + ")";
}
}
188 changes: 182 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,186 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Duke {

private Scanner input = new Scanner(System.in);
private ArrayList<Task> tasks = new ArrayList<>();

public void start() {
String logo = "\t ____ _ \n"
+ "\t | _ \\ _ _| | _____ \n"
+ "\t | | | | | | | |/ / _ \\\n"
+ "\t | |_| | |_| | < __/\n"
+ "\t |____/ \\__,_|_|\\_\\___|\n";
System.out.println(logo);
System.out.println("\t Hello! I'm Duke");
System.out.println("\t What can I do for you?\n");
}

public void display() {
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
}

public void mark(String command) throws DukeException{
if (command.trim().equals("mark")) {
throw new DukeException("\t ☹ OOPS!!! The description of a mark cannot be empty.\n");
}
try {
int index = Integer.parseInt(command.split(" ")[1]) - 1;
if (index + 1 > tasks.size() || index < 0) {
throw new DukeException("\t ☹ OOPS!!! Please input a valid number.\n");
}
tasks.get(index).mark();
} catch (NumberFormatException ex) {
System.out.println("\t ☹ OOPS!!! Please input a valid number.\n");
}
}

public void unmark(String command) throws DukeException{
if (command.trim().equals("mark")) {
throw new DukeException("\t ☹ OOPS!!! The description of a unmark cannot be empty.\n");
}
try {
int index = Integer.parseInt(command.split(" ")[1]) - 1;
if (index + 1 > tasks.size() || index < 0) {
throw new DukeException("\t ☹ OOPS!!! Please input a valid number.\n");
} else if (tasks.get(index).getStatusIcon().equals(" ")) {
throw new DukeException("\t ☹ OOPS!!! This task has not been marked yet.\n");
}
tasks.get(index).unmark();
} catch (NumberFormatException ex) {
System.out.println("\t ☹ OOPS!!! Please input a valid number.\n");
}
}

public void list() {
for (int i = 0; i < tasks.size(); i++) {
System.out.print("\t " + (i + 1) + "." + tasks.get(i).toString() + "\n");
}
System.out.print("\n");
}

public void addTask(Task task) {
tasks.add(task);
System.out.println("\t Got it. I've added this task:\n"
Copy link

Choose a reason for hiding this comment

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

I like what you did here - indenting and spacing a sentence into parts that are more readable!

+ "\t\t "+ tasks.get(tasks.size() - 1).toString()
+ "\n\t Now you have " + tasks.size() + " tasks in the list.\n");
}
public void todo(String command) throws DukeException {
if (command.trim().equals("todo")) {
throw new DukeException("\t ☹ OOPS!!! The description of a todo cannot be empty.\n");
}
String description = command.split(" ", 2)[1];
Todo todo = new Todo(description);
addTask(todo);
}

public void deadline(String command) throws DukeException {
if (command.trim().equals("deadline")) {
throw new DukeException("\t ☹ OOPS!!! The description of a deadline cannot be empty.\n");
} else if (command.trim().contains(" /by ") == false) {
throw new DukeException("\t ☹ OOPS!!! There is no deadline date or the wrong format\n");
}

command = command.split(" ", 2)[1];
if (command.startsWith("/by")) {
throw new DukeException("☹ OOPS!!! The description of a deadline cannot be empty.\n");
} else if (command.endsWith("/by")) {
throw new DukeException(("☹ OOPS!!! The due date of a deadline cannot be empty.\n"));
}

String info[] = command.split(" /by ");
Copy link

Choose a reason for hiding this comment

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

Perhaps we should put the [] right after the String instead even though this is valid too?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for pointing them out!

String description = info[0];
String by = info[1];
Copy link

Choose a reason for hiding this comment

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

Maybe instead of just "by", we can use a variable name that indicates that this is a date?

Deadline deadline = new Deadline(description, by);
addTask(deadline);
}

public void event(String command) throws DukeException{
command = command.trim();
if (command.equals("event")) {
throw new DukeException("\t ☹ OOPS!!! The description of a event cannot be empty.\n");
} else if (command.contains(" /from ") == false || command.contains(" /to ") == false) {
throw new DukeException("\t ☹ OOPS!!! The from date or due date of a deadline cannot be empty.\n"
+ "\t Or the format is wrong.\n");
}

command = command.split(" ", 2)[1];
if (command.startsWith("/from") || command.endsWith("/to") || command.contains("/from /to")) {
throw new DukeException("\t ☹ OOPS!!! The description, from date or due date of a event cannot be empty.\n");
}

String info[] = command.split(" /from ");
Copy link

Choose a reason for hiding this comment

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

Perhaps the naming of this variable can be a standard plural noun instead?

String description = info[0];
String dates[] = info[1].split(" /to ");
String from = dates[0];
String to = dates[1];

Event event = new Event(description, from, to);
addTask(event);
}

public void delete(String command) throws DukeException {
command = command.trim();
if (command.equals("delete")) {
throw new DukeException("\t ☹ OOPS!!! The description of a delete cannot be empty.\n");
}
int index;
try {
index = Integer.parseInt(command.split(" ")[1]);
} catch (NumberFormatException ex) {
throw new DukeException("\t ☹ OOPS!!! Please input a valid number.\n");
}
if (index < 1 || index > tasks.size()) {
throw new DukeException("\t ☹ OOPS!!! The input is out of range.\n");
}
System.out.println("\t Noted. I've removed this task:\n"
+ "\t\t " + tasks.get(index - 1).toString());
tasks.remove(index - 1);
System.out.println("\t Now you have " + tasks.size() + " tasks in the list.\n");
}

public void run() {
start();
while (true) {
String command = input.nextLine();
try {
if (command.equals("bye")) {
display();
System.out.println("\t Bye. Hope to see you again soon!");
break;
} else if (command.equals("list")) {
display();
list();
} else if (command.startsWith("mark")) {
display();
mark(command);
} else if (command.startsWith("unmark")) {
display();
unmark(command);
} else if (command.startsWith("todo")) {
display();
todo(command);
} else if (command.startsWith("deadline")) {
display();
deadline(command);
} else if (command.startsWith("event")) {
display();
event(command);
} else if (command.startsWith("delete")) {
display();
delete(command);
} else {
display();
System.out.println("\t ☹ OOPS!!! I'm sorry, but I don't know what that means.\n");
}
} catch (DukeException e) {
System.out.println(e.getMessage());
}
}
}
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
Duke duke = new Duke();
duke.run();
}
}
6 changes: 6 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class DukeException extends Exception{

public DukeException(String message) {
super(message);
}
}
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 from;
protected String to;

public Event(String description, String from, String to) {
super(description);
this.from = from;
this.to = to;
}
@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")";
}
}
30 changes: 30 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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" : " ");
}

public void mark() {
this.isDone = true;
System.out.println("\t Nice! I've marked this task as done:\n"
+ "\t\t [X] " + this.description + "\n");
}

public void unmark() {
this.isDone = false;
System.out.println("\t OK, I've marked this task as not done yet:\n"
+ "\t\t [ ] " + this.description + "\n");
}

@Override
public String toString() {
return " [" + getStatusIcon() + "] " + this.description;
}
}
10 changes: 10 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Todo extends Task{
public Todo(String description) {
super(description);
}

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

Hello! I'm Duke
What can I do for you?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Got it. I've added this task:
[D] [ ] return book (by: Sunday)
Now you have 2 tasks in the list.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1.[T] [ ] borrow book
2.[D] [ ] return book (by: Sunday)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Nice! I've marked this task as done:
[X] return book

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Got it. I've added this task:
[E] [ ] project meeting (from: Mon 2pm to: 4pm)
Now you have 3 tasks in the list.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Nice! I've marked this task as done:
[X] project meeting

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

OK, I've marked this task as not done yet:
[ ] return book

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1.[T] [ ] borrow book
2.[D] [ ] return book (by: Sunday)
3.[E] [X] project meeting (from: Mon 2pm to: 4pm)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Bye. Hope to see you again soon!
9 changes: 9 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
todo borrow book
deadline return book /by Sunday
list
mark 2
event project meeting /from Mon 2pm /to 4pm
mark 3
unmark 2
list
bye
2 changes: 2 additions & 0 deletions text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ if exist ACTUAL.TXT del ACTUAL.TXT

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 **********
exit /b 1
Expand Down