-
Notifications
You must be signed in to change notification settings - Fork 434
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
Alex Setyawan iP #476
base: master
Are you sure you want to change the base?
Alex Setyawan iP #476
Changes from 9 commits
55f9f9f
f837ddb
a6f7324
fbeec99
95ae554
dcaa40e
8282fc9
23725d6
0c94cc6
d9be119
40c2f1c
b8a17cf
ecd3039
81fa62e
bc932d1
8e740c8
c70d672
6081c95
f88ac1b
1aab432
8f524c4
150effc
e8807b5
e787551
5d7d33e
c555db6
d8c5937
ac056d1
2e2cad8
5c97137
918454b
345dd2c
8509e36
f8cef40
ee52925
bac18eb
f06896e
900fc2f
566c52f
7016d82
d29dc09
3b5168f
8abb368
bde67b9
ac84b3b
c4d739c
c82256c
66cec4a
12919e9
aba319d
05dd207
edc80be
4eb286f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import java.util.*; | ||
|
||
public class Awex { | ||
public static void message() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good abstraction of the message to display the list of commands available. Perhaps a better and more specific variable name could be used here to describe this function? For example you could rename it to: |
||
System.out.println("Input type must be one of:"); | ||
System.out.println(" 1. list"); | ||
System.out.println(" 2. mark <task number>"); | ||
System.out.println(" 3. unmark <task number>"); | ||
System.out.println(" 4. todo <task>"); | ||
System.out.println(" 5. deadline <task> /by <deadline>"); | ||
System.out.println(" 6. event <task> /from <start> /to <end>"); | ||
System.out.println("Type 'bye' to exit."); | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Hello! I'm AWEX!\nWhat can I do for you?"); | ||
LinkedList<Task> list = new LinkedList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why a LinkedList is used instead of an ArrayList? Indeed a LinkedList works similar to an ArrayList, although their use cases may vary depending on the scenario. Here is some research that I did: ArrayList vs LinkedList |
||
Scanner sc = new Scanner(System.in); | ||
String next = sc.nextLine(); | ||
String[] arr = next.split(" "); | ||
while (!next.equals("bye")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of if-else statements to check and parse inputs! However, perhaps you could abstract out this method and also do consider using switch-case statements to improve performance. |
||
if (next.equals("list")) { | ||
if (arr.length > 1) { | ||
message(); | ||
} else if (list.isEmpty()){ | ||
System.out.println("List is empty."); | ||
} else { | ||
System.out.println("Here are the tasks in your list:"); | ||
int len = list.size(); | ||
for (int i = 1; i <= len; i++) { | ||
System.out.println(i + "." + list.get(i - 1).showAll()); | ||
} | ||
} | ||
} else if (arr[0].equals("mark")) { | ||
String[] array = next.split(" "); | ||
if (array.length != 2) { | ||
System.out.println("Format should be 'mark <task number>'"); | ||
} else { | ||
int i = Integer.parseInt(array[1]); | ||
int len = list.size(); | ||
if (i > len) { | ||
System.out.println("List has only " + len + " tasks."); | ||
} else { | ||
Task t = list.get(i - 1); | ||
t.mark(); | ||
System.out.println(" " + t.showAll()); | ||
} | ||
} | ||
} else if (arr[0].equals("unmark")) { | ||
String[] array = next.split(" "); | ||
if (array.length != 2) { | ||
System.out.println("Format should be 'unmark <task number>'"); | ||
} else { | ||
int i = Integer.parseInt(array[1]); | ||
int len = list.size(); | ||
if (i > len) { | ||
System.out.println("List has only " + len + " tasks."); | ||
} else { | ||
Task t = list.get(i - 1); | ||
t.unmark(); | ||
System.out.println(" " + t.showAll()); | ||
} | ||
} | ||
} else if (arr[0].equals("delete")) { | ||
String[] array = next.split(" "); | ||
if (array.length != 2) { | ||
System.out.println("Format should be 'delete <task number>'"); | ||
} else { | ||
int i = Integer.parseInt(array[1]); | ||
int len = list.size(); | ||
if (i > len) { | ||
System.out.println("List has only " + len + " tasks."); | ||
} else { | ||
System.out.println("Noted. I've removed this task:"); | ||
System.out.println(" " + list.remove(i - 1).showAll()); | ||
System.out.println("Now you have " + list.size() + " tasks in the list."); | ||
} | ||
} | ||
} else { | ||
Task t; | ||
if (arr[0].equals("todo")) { | ||
if (arr.length > 1) { | ||
t = new TodoTask(arr[1]); | ||
} else { | ||
System.out.println("Format should be 'todo <task>'"); | ||
next = sc.nextLine(); | ||
arr = next.split(" ", 2); | ||
continue; | ||
} | ||
} else if (arr[0].equals("deadline")) { | ||
String[] array = next.split("/"); | ||
if (array.length != 2) { | ||
System.out.println("Format should be 'deadline <task> /by <deadline>'"); | ||
next = sc.nextLine(); | ||
arr = next.split(" ", 2); | ||
continue; | ||
} | ||
String[] hasWhat = arr[1].split("/", 2); | ||
String[] hasTime = hasWhat[1].split(" ", 2); | ||
t = new DeadlineTask(hasWhat[0], hasTime[1]); | ||
} else if (arr[0].equals("event")){ | ||
String[] array = next.split("/"); | ||
if (array.length != 3) { | ||
System.out.println("Format should be 'event <task> /from <start> /to <end>'"); | ||
next = sc.nextLine(); | ||
arr = next.split(" ", 2); | ||
continue; | ||
} | ||
String[] hasWhat = arr[1].split("/", 2); | ||
String[] hasTimes = hasWhat[1].split("/", 2); | ||
String[] hasStart = hasTimes[0].split(" ", 2); | ||
String[] hasEnd = hasTimes[1].split(" ", 2); | ||
t = new EventTask(hasWhat[0], hasStart[1], hasEnd[1]); | ||
} else { | ||
message(); | ||
next = sc.nextLine(); | ||
arr = next.split(" ", 2); | ||
continue; | ||
} | ||
list.add(t); | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + t.showAll()); | ||
System.out.println("Now you have " + list.size() + " tasks in the list."); | ||
} | ||
next = sc.nextLine(); | ||
arr = next.split(" ", 2); | ||
} | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class DeadlineTask extends Task { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of inheritance! |
||
private String type; | ||
private String deadline; | ||
public DeadlineTask(String what, String deadline) { | ||
super(what); | ||
this.type = "[D]"; | ||
this.deadline = deadline; | ||
} | ||
public String showAll() { | ||
return this.type + super.showAll() + "(by: " + this.deadline + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class EventTask extends Task { | ||
private String type; | ||
private String start; | ||
private String end; | ||
public EventTask(String what, String start, String end) { | ||
super(what); | ||
this.type = "[E]"; | ||
this.start = start; | ||
this.end = end; | ||
} | ||
public String showAll() { | ||
return this.type + super.showAll() | ||
+ "(from: " + this.start + " to: " + this.end + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
public class Task { | ||
private String what; | ||
private String done; | ||
|
||
public Task(String what) { | ||
this.what = what; | ||
this.done = "[ ]"; | ||
} | ||
|
||
public String showAll() { | ||
return this.done + " " + this.what; | ||
} | ||
|
||
public void mark() { | ||
this.done = "[X]"; | ||
System.out.println("Nice! I've marked this task as done:"); | ||
} | ||
|
||
public void unmark() { | ||
this.done = "[ ]"; | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
public class TodoTask extends Task { | ||
private String type; | ||
|
||
/** | ||
* Constuctor for Task object of type "todo" | ||
* | ||
* @param what description of the task | ||
*/ | ||
public TodoTask(String what) { | ||
super(what); | ||
this.type = "[T]"; | ||
} | ||
|
||
/** | ||
* Returns string showing task type, completion status and description. | ||
* | ||
* @return string of task type, marked/unmarked status and description | ||
*/ | ||
public String showAll() { | ||
return this.type + super.showAll(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
Got it. I've added this task: | ||
[T][ ] borrow book | ||
Now you have 1 tasks in the list. | ||
Here are the tasks in your list: | ||
1.[T][ ] borrow book | ||
Got it. I've added this task: | ||
[D][ ] return book (by: Sunday) | ||
Now you have 2 tasks in the list. | ||
Here are the tasks in your list: | ||
1.[T][ ] borrow book | ||
2.[D][ ] return book (by: Sunday) | ||
Got it. I've added this task: | ||
[E][ ] project meeting (from: Mon 2pm to: 4pm) | ||
Now you have 3 tasks in the list. | ||
Here are the tasks in your list: | ||
1.[T][ ] borrow book | ||
2.[D][ ] return book (by: Sunday) | ||
3.[E][ ] project meeting (from: Mon 2pm to: 4pm) | ||
Nice! I've marked this task as done: | ||
[T][X] borrow book | ||
Nice! I've marked this task as done: | ||
[E][X] project meeting (from: Mon 2pm to: 4pm) | ||
Here are the tasks in your list: | ||
1.[T][X] borrow book | ||
2.[D][ ] return book (by: Sunday) | ||
3.[E][X] project meeting (from: Mon 2pm to: 4pm) | ||
OK, I've marked this task as not done yet: | ||
[T][ ] borrow book | ||
OK, I've marked this task as not done yet: | ||
[E][ ] project meeting (from: Mon 2pm to: 4pm) | ||
Here are the tasks in your list: | ||
1.[T][ ] borrow book | ||
2.[D][ ] return book (by: Sunday) | ||
3.[E][ ] project meeting (from: Mon 2pm to: 4pm) | ||
Bye. Hope to see you again soon! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
todo borrow book | ||
list | ||
deadline return book /by Sunday | ||
list | ||
event project meeting /from Mon 2pm /to 4pm | ||
list | ||
mark 1 | ||
mark 3 | ||
list | ||
unmark 1 | ||
unmark 3 | ||
list | ||
bye |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you could try to avoid the use of wildcard imports here as it could lead to import conflicts.