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

[Siti Nadiah] iP #48

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e7ddeaf
Add greeting
sitinadiah25 Jan 21, 2020
9b36508
Add greeting
sitinadiah25 Jan 27, 2020
7dbafe5
Add List
sitinadiah25 Jan 27, 2020
61e8429
Add Mark as Done
sitinadiah25 Jan 27, 2020
50eaba3
Refactor messages
sitinadiah25 Jan 31, 2020
bde2274
Add Task subclasses
sitinadiah25 Jan 31, 2020
ec8b25f
Add automated testing
sitinadiah25 Feb 2, 2020
76c925a
Revert "Add automated testing"
sitinadiah25 Feb 2, 2020
92bd1da
Add automated testing
sitinadiah25 Feb 2, 2020
c0b1feb
Remove new scanner
sitinadiah25 Feb 2, 2020
19bfb8e
Improve code quality #1
sitinadiah25 Feb 2, 2020
2f66be2
Refactor command variables
sitinadiah25 Feb 3, 2020
d5666fa
Add error handling
sitinadiah25 Feb 8, 2020
04d0c6e
Fix minor bugs
sitinadiah25 Feb 8, 2020
0cb741a
Merge pull request #1 from sitinadiah25/branch-Level-5
sitinadiah25 Feb 8, 2020
3a90e6c
Add newline for comments
sitinadiah25 Feb 10, 2020
e785bea
Add static int variable
sitinadiah25 Feb 10, 2020
4ecd16b
Add task package
sitinadiah25 Feb 12, 2020
7976315
Add delete method
sitinadiah25 Feb 15, 2020
1646488
Add save method
sitinadiah25 Feb 15, 2020
0955a30
Fix save data
sitinadiah25 Feb 15, 2020
eeef120
Merge pull request #2 from sitinadiah25/branch-level-6
sitinadiah25 Feb 16, 2020
381f0db
Add open saved data
sitinadiah25 Feb 16, 2020
f416108
Merge branch 'master' into branch-level-7
sitinadiah25 Feb 16, 2020
f6967be
Merge pull request #3 from sitinadiah25/branch-level-7
sitinadiah25 Feb 16, 2020
805d350
Fix file append
sitinadiah25 Feb 16, 2020
2736fb6
Fix file object
sitinadiah25 Feb 17, 2020
9aec6d7
Add Ui class
sitinadiah25 Feb 28, 2020
f1bdc46
Add Parser class
sitinadiah25 Feb 28, 2020
246787c
Add Storage class
sitinadiah25 Feb 28, 2020
830107d
Add more OOP
sitinadiah25 Feb 29, 2020
cd2a67d
Add find method
sitinadiah25 Feb 29, 2020
d669224
Revert "Add find method"
sitinadiah25 Feb 29, 2020
a887a50
Add find method
sitinadiah25 Feb 29, 2020
fd6f233
Add JavaDoc
sitinadiah25 Feb 29, 2020
c9b40ec
Merge pull request #5 from sitinadiah25/branch-A-JavaDoc
sitinadiah25 Feb 29, 2020
56230c0
Merge branch 'branch-Level-9' into master
sitinadiah25 Feb 29, 2020
e5e77a6
Merge pull request #6 from sitinadiah25/master
sitinadiah25 Feb 29, 2020
f305d30
Merge pull request #7 from sitinadiah25/branch-Level-9
sitinadiah25 Feb 29, 2020
10b4634
Update README.md
sitinadiah25 Feb 29, 2020
cea5534
Merge branch 'master' of https://github.com/sitinadiah25/duke
sitinadiah25 Feb 29, 2020
0aeb205
Update README.md
sitinadiah25 Feb 29, 2020
eeb0a39
Set theme jekyll-theme-hacker
sitinadiah25 Feb 29, 2020
adca7ed
Update README.md
sitinadiah25 Feb 29, 2020
3d3001a
Update README.md
sitinadiah25 Feb 29, 2020
d882c6f
Update README.md
sitinadiah25 Feb 29, 2020
08bec3c
Update README.md
sitinadiah25 Feb 29, 2020
a23257e
Update README.md
sitinadiah25 Feb 29, 2020
76037ed
Update README.md
sitinadiah25 Feb 29, 2020
ddefeb2
Update README.md
sitinadiah25 Mar 3, 2020
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
21 changes: 21 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Deadline extends Task {
protected String by;

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

public String getBy() {
return by;
}

public void setBy(String by) {
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by: " + this.by + ")";
}
}
140 changes: 134 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,138 @@
import java.util.Scanner;

public class Duke {

private static int NUM_OF_TASK = 0;
private static String LINE = "____________________________________________________________\n";
private static final String BYE_COMMAND = "bye";
private static final String LIST_COMMAND = "list";
private static final String DONE_COMMAND = "done";
private static final String TODO_COMMAND = "todo";
private static final String EVENT_COMMAND = "event";
private static final String DEADLINE_COMMAND = "deadline";

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

private static void runChatbot() {
Task[] Tasks = new Task[100];

Choose a reason for hiding this comment

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

Delete some useless blank lines.

Scanner in = new Scanner(System.in);
String arr[] = getCommand(in);

while (true) {
runCommand(arr, Tasks, in);
arr = getCommand(in);
}
}

private static String[] getCommand(Scanner in) {
String s = in.nextLine();
String arr[] = s.split(" ", 2);
return arr;
}

private static void runCommand(String[] arr, Task[] Tasks, Scanner in) {
switch (arr[0]) {
case (BYE_COMMAND):
printExitMessage();
case (LIST_COMMAND):
printList(Tasks);
break;
case (DONE_COMMAND):
int taskNum = Integer.parseInt(arr[1]);
taskNum--;
Tasks[taskNum].setDone(true);
printDone(Tasks[taskNum]);
break;
case (TODO_COMMAND):
Tasks[NUM_OF_TASK] = new Todo(arr[1]);
printConfirm(Tasks[NUM_OF_TASK]);
break;
case (DEADLINE_COMMAND):
String arr2[] = arr[1].split("/by ", 2);
Tasks[NUM_OF_TASK] = new Deadline(arr2[0], arr2[1]);
printConfirm(Tasks[NUM_OF_TASK]);
break;
case (EVENT_COMMAND):
arr2 = arr[1].split("/at ", 2);
Tasks[NUM_OF_TASK] = new Event(arr2[0], arr2[1]);
printConfirm(Tasks[NUM_OF_TASK]);
break;
}
}

private static void printDone(Task task) {
System.out.println(LINE);
System.out.println("Nice! I've marked this task as done: ");
System.out.println(" " + task);
System.out.println(LINE);
}

private static void printConfirm(Task task) {
System.out.println(LINE);
System.out.println("Got it! I've added this task:");
System.out.println(" " + task);
int num = NUM_OF_TASK + 1;
System.out.println("Now you have " + num + " task(s) in the list.");
System.out.println(LINE);
NUM_OF_TASK++;
}

private static void printExitMessage() {
String outro = "Bye. Hope to see you again soon!";
System.out.println(LINE);
System.out.println(outro);
System.out.println(LINE);
System.exit(0);
}

private static void printWelcomeMessage() {
String tos = "──────────▄▄▄▄▄▄▄▄▄▄▄──────────\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 your mascot!

"─────▄▄▀▀▀▀──────────▀▀▄▄──────\n" +

Choose a reason for hiding this comment

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

I like too!👻

"───▄▀───────────────────▀▀▄────\n" +
"──█────────────────────────█───\n" +
"─█─────────────────────▄▀▀▀▀▀█▄\n" +
"█▀────────────────────█────▄███\n" +
"█─────────────────────█────▀███\n" +
"█─────▄▀▀██▀▄─────────█───────█\n" +
"█────█──████─█─────────▀▄▄▄▄▄█─\n" +
"█────█──▀██▀─█───────────────█─\n" +
"█────█───────█──────────────▄▀─\n" +
"█────▀▄─────▄▀──▄▄▄▄▄▄▄▄▄───█──\n" +
"█──────▀▀▀▀▀────█─█─█─█─█──▄▀──\n" +
"─█──────────────▀▄█▄█▄█▀──▄▀───\n" +
"──█──────────────────────▄▀────\n" +
"───▀▀▀▄──────────▄▄▄▄▄▄▀▀──────\n" +
"────▄▀─────────▀▀──▄▀──────────\n" +
"──▄▀───────────────█───────────\n" +
"─▄▀────────────────█──▄▀▀▀█▀▀▄─\n" +
"─█────█──█▀▀▀▄─────█▀▀────█──█─\n" +
"▄█────▀▀▀────█─────█────▀▀───█─\n" +
"█▀▄──────────█─────█▄────────█─\n" +
"█──▀▀▀▀▀█▄▄▄▄▀─────▀█▀▀▀▄▄▄▄▀──\n" +
"█───────────────────▀▄─────────\n";

System.out.println("What is up my dudes!\n" + tos);

String intro = "____________________________________________________________\n" +
Copy link

Choose a reason for hiding this comment

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

Maybe you could use the LINE constant for this line?

" It is I, Bob!\n" +
" How may I spook you today?\n" +
"____________________________________________________________\n";

System.out.println(intro);
}

public static void printList(Task[] Task) {
System.out.println(LINE);
System.out.println("Here are the tasks in your list: \n");
for (int i = 0; i < NUM_OF_TASK; i++) {
int num = i + 1;
System.out.println(num + ". " + Task[i]);
}
System.out.println(LINE);
}
}

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

protected String time;

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

public String getTime() {
return time;
}

public void setTime(String time) {
this.time = time;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(at: " + this.time + ")";
}
}
47 changes: 47 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
public class Task {
protected String description;
protected boolean isDone;
protected int num;

private static int curr = 1;

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

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

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public boolean isDone() {
return isDone;
}

public void setDone(boolean done) {
isDone = done;
}

public int getNum() {
return num;
}

public void setNum(int num) {
this.num = num;
}

@Override
public String toString() {
return "[" + this.getStatusIcon() + "] " + 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();
}
}
105 changes: 105 additions & 0 deletions text-ui-test/EXPECTED.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
What is up my dudes!
──────────▄▄▄▄▄▄▄▄▄▄▄──────────
─────▄▄▀▀▀▀──────────▀▀▄▄──────
───▄▀───────────────────▀▀▄────
──█────────────────────────█───
─█─────────────────────▄▀▀▀▀▀█▄
█▀────────────────────█────▄███
█─────────────────────█────▀███
█─────▄▀▀██▀▄─────────█───────█
█────█──████─█─────────▀▄▄▄▄▄█─
█────█──▀██▀─█───────────────█─
█────█───────█──────────────▄▀─
█────▀▄─────▄▀──▄▄▄▄▄▄▄▄▄───█──
█──────▀▀▀▀▀────█─█─█─█─█──▄▀──
─█──────────────▀▄█▄█▄█▀──▄▀───
──█──────────────────────▄▀────
───▀▀▀▄──────────▄▄▄▄▄▄▀▀──────
────▄▀─────────▀▀──▄▀──────────
──▄▀───────────────█───────────
─▄▀────────────────█──▄▀▀▀█▀▀▄─
─█────█──█▀▀▀▄─────█▀▀────█──█─
▄█────▀▀▀────█─────█────▀▀───█─
█▀▄──────────█─────█▄────────█─
█──▀▀▀▀▀█▄▄▄▄▀─────▀█▀▀▀▄▄▄▄▀──
█───────────────────▀▄─────────

____________________________________________________________
It is I, Bob!
How may I spook you today?
____________________________________________________________

____________________________________________________________

Got it! I've added this task:
[T][✘] call dentist
Now you have 1 task(s) in the list.
____________________________________________________________

____________________________________________________________

Got it! I've added this task:
[T][✘] make appointment at clinic
Now you have 2 task(s) in the list.
____________________________________________________________

____________________________________________________________

Got it! I've added this task:
[E][✘] team meeting (at: AS3 10 Feb 10am)
Now you have 3 task(s) in the list.
____________________________________________________________

____________________________________________________________

Got it! I've added this task:
[D][✘] OP1 research (by: 6 Feb)
Now you have 4 task(s) in the list.
____________________________________________________________

____________________________________________________________

Got it! I've added this task:
[E][✘] Project Link sales (at: 4 Feb 1pm)
Now you have 5 task(s) in the list.
____________________________________________________________

____________________________________________________________

Here are the tasks in your list:

1. [T][✘] call dentist
2. [T][✘] make appointment at clinic
3. [E][✘] team meeting (at: AS3 10 Feb 10am)
4. [D][✘] OP1 research (by: 6 Feb)
5. [E][✘] Project Link sales (at: 4 Feb 1pm)
____________________________________________________________

____________________________________________________________

Nice! I've marked this task as done:
[T][✓] make appointment at clinic
____________________________________________________________

____________________________________________________________

Nice! I've marked this task as done:
[D][✓] OP1 research (by: 6 Feb)
____________________________________________________________

____________________________________________________________

Here are the tasks in your list:

1. [T][✘] call dentist
2. [T][✓] make appointment at clinic
3. [E][✘] team meeting (at: AS3 10 Feb 10am)
4. [D][✓] OP1 research (by: 6 Feb)
5. [E][✘] Project Link sales (at: 4 Feb 1pm)
____________________________________________________________

____________________________________________________________

Bye. Hope to see you again soon!
____________________________________________________________

10 changes: 10 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
todo call dentist
todo make appointment at clinic
event team meeting /at AS3 10 Feb 10am
deadline OP1 research /by 6 Feb
event Project Link sales /at 4 Feb 1pm
list
done 2
done 4
list
bye
Loading