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

[Zhang Yubin] ip #471

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
a320dbd
Level-1
Kimowarui Aug 19, 2021
56dd70a
Level-2
Kimowarui Aug 19, 2021
98b4bdc
Level-3
Kimowarui Aug 19, 2021
5bf86fe
Level-4
Kimowarui Aug 19, 2021
15b129b
Level-5
Kimowarui Aug 19, 2021
9c82281
Level-6
Kimowarui Aug 19, 2021
79c9bdf
A-TextUiTesting
Kimowarui Aug 26, 2021
010e34e
Some modifications from last week ip
Kimowarui Aug 26, 2021
0cc48f4
Auto Save
Kimowarui Aug 26, 2021
e4d564e
Auto Date and Times
Kimowarui Aug 26, 2021
e1e5885
Make the program more OOP
Kimowarui Sep 15, 2021
a046802
Divide classes into packages
Kimowarui Sep 15, 2021
13513a0
Add JUnit tests
Kimowarui Sep 15, 2021
e23ab33
Add JUnit tests
Kimowarui Sep 15, 2021
9e90dc7
Add JavaDoc comments
Kimowarui Sep 15, 2021
d9cd2c8
Tweak the code to comply with a coding standard
Kimowarui Sep 15, 2021
6f75690
Give users a way to find a task by searching for a keyword.
Kimowarui Sep 15, 2021
a8adc43
Merge branch 'branch-A-CodingStandard'
Kimowarui Sep 15, 2021
ac088aa
Merge branch 'branch-Level-9'
Kimowarui Sep 15, 2021
6f56ccd
Merge remote-tracking branch 'origin/add-gradle-support' into branch-…
Kimowarui Sep 17, 2021
5ab9d28
Fix some coding style using Gradle
Kimowarui Sep 18, 2021
3e1041e
Add a GUI to Duke
Kimowarui Sep 19, 2021
55e5b87
Make it more OOP
Kimowarui Sep 20, 2021
8397082
Add Assertions feature: Assert input given by user will always be valid
Kimowarui Sep 20, 2021
14e72e8
Improve code quality
Kimowarui Sep 20, 2021
1a5e30c
Merge branch 'branch-A-CodeQuality'
Kimowarui Sep 20, 2021
4b75f2c
Add snooze feature selected from category B, C, or D
Kimowarui Sep 20, 2021
c3b7bdd
Improve the GUI
Kimowarui Sep 21, 2021
192bb10
Update README.md
Kimowarui Sep 21, 2021
a4539eb
Add files via upload
Kimowarui Sep 21, 2021
8d35eac
Update README.md
Kimowarui Sep 21, 2021
fec1ca4
Set theme jekyll-theme-architect
Kimowarui Sep 21, 2021
99fe33e
Update README.md
Kimowarui Sep 21, 2021
67a5a7a
Set theme jekyll-theme-hacker
Kimowarui Sep 21, 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
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadline extends Task {

protected String by;

Choose a reason for hiding this comment

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

Should this be more specific as to what it refers to?


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

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
76 changes: 75 additions & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,84 @@
import com.sun.source.tree.DoWhileLoopTree;

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

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
String line = "____________________________________________________________";
ArrayList<Task> task = new ArrayList<>();
System.out.println("Hello from\n" + logo + line + "\nWhat can I do for you?\n" + line);

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

while(!input.equals("bye")) {
String[] parts = input.split(" ");
if(input.equals("list")) {

Choose a reason for hiding this comment

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

Might be cleaner to change to switch statements

int i = 1;
System.out.println(line);
System.out.println("Here are the tasks in your list:");
for(Task t: task) {
System.out.println(i + "." + t.toString());
i++;
}
System.out.println(line);
} else if (parts[0].equals("done")) {
int index = Integer.valueOf(parts[1]);
Task thisTask = task.get(index - 1);
thisTask.markDone();
System.out.println(line);
System.out.println("Nice! I've marked this task as done:\n" + thisTask.toString());
System.out.println(line);

Choose a reason for hiding this comment

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

Maybe for this portion can create an additional class(Example UI) to do all this line of code for you, and just need to call that function from the class so that it looks much neater. Can also be done so on your other if-else statements

} else if (parts[0].equals("delete")) {
int index = Integer.valueOf(parts[1]);
Task thisTask = task.remove(index - 1);
System.out.println(line);
System.out.println("Noted I've removed this task:\n" + thisTask.toString());
System.out.println("Now you have " + task.size() + " tasks in your list");
System.out.println(line);
} else if (parts.length == 1) {
System.out.println(line);
System.out.println("OOPS!!! The description of a " + parts[0] + " cannot be empty.");
System.out.println(line);
} else if (parts[0].equals("deadline")){
String[] part2 = input.split("/by ");
String description = part2[0].split("deadline ")[1];
Task deadline = new Deadline(description, part2[1]);
System.out.println(line + "\n" + "added: " + deadline.toString());
task.add(deadline);
System.out.println("Now you have " + task.size() + " tasks in your list");
System.out.println(line);
} else if (parts[0].equals("event")){
String[] part2 = input.split("/at ");
String description = part2[0].split("event ")[1];
Task event = new Event(description, part2[1]);
System.out.println(line + "\n" + "added: " + event.toString());
task.add(event);
System.out.println("Now you have " + task.size() + " tasks in your list");
System.out.println(line);
} else if (parts[0].equals("todo")){

Choose a reason for hiding this comment

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

I think there should be a space between ")" and "{", so ) {

String[] part2 = input.split("/");
String description = part2[0].split("todo ")[1];
Task todo = new Todo(description);
System.out.println(line + "\n" + "added: " + todo.toString());
task.add(todo);
System.out.println("Now you have " + task.size() + " tasks in your list");
System.out.println(line);
} else {
System.out.println(line);
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(");
System.out.println(line);
}
input = s.nextLine();
}

System.out.println(line + "\nBye. Hope to see you again soon!\n" + line);
}
}
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;

Choose a reason for hiding this comment

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

Might be good to use a more desceiptive name for the variable


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

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

Choose a reason for hiding this comment

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

Ternary operators might look cleaner when seperated into multiple lines, and there is no need for the brackets.

}

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

@Override
public String toString(){
return "[" + this.getStatusIcon() + "] " + this.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]" + super.toString();
}
}
35 changes: 32 additions & 3 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
Hello from
____ _
| _ \ _ _| | _____
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

____________________________________________________________
What can I do for you?
____________________________________________________________
____________________________________________________________
added: [T][ ] borrow book
Now you have 1 tasks in your list
____________________________________________________________
____________________________________________________________
added: [D][ ] return book (by: Sunday)
Now you have 2 tasks in your list
____________________________________________________________
____________________________________________________________
added: [E][ ] project meeting (at: Mon 2-4pm)
Now you have 3 tasks in your list
____________________________________________________________
____________________________________________________________
added: [D][ ] return book (by: June 6th)
Now you have 4 tasks in your list
____________________________________________________________
____________________________________________________________
added: [T][ ] join sports club
Now you have 5 tasks in your list
____________________________________________________________
____________________________________________________________
Nice! I've marked this task as done:
[E][X] project meeting (at: Mon 2-4pm)
____________________________________________________________
____________________________________________________________
Bye. Hope to see you again soon!
____________________________________________________________
7 changes: 7 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
todo borrow book
deadline return book /by Sunday
event project meeting /at Mon 2-4pm
deadline return book /by June 6th
todo join sports club
done 3
bye