-
Notifications
You must be signed in to change notification settings - Fork 270
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
[Vanessa] iP #314
base: master
Are you sure you want to change the base?
[Vanessa] iP #314
Changes from 6 commits
d839859
253e8b0
3427794
e6d31a7
9dbe82d
be1a567
3ec0b1a
0f521e8
8f52035
8e8980b
2c96f56
733ba9a
4aa2a9e
54cd499
57426c5
95693f5
76d36c7
8d822c0
a30df56
2fa50d7
d48749e
9095cf4
06be999
35b7840
8315ecb
3aea752
714e529
0bccd26
3199aad
71183f3
3d78dc3
b76a2d5
6389773
f260392
5bd4d38
bbdb6ff
fd09a66
9587526
99e35f2
ccee2a0
b7b8d31
fea6ca1
7d58559
196330e
6637131
02f6bbd
fa0b705
de0f6b7
4e6a065
e07b092
4d9ff92
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,13 @@ | ||
public class Deadlines extends Task { | ||
String date; | ||
|
||
public Deadlines(String str, String date) { | ||
super(str); | ||
this.date = date; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "D" + super.toString() + " by: " + date; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Event extends Task { | ||
String date; | ||
|
||
public Event(String str, String date) { | ||
super(str); | ||
this.date = date; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "E" + super.toString() + " on: " + date; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import java.sql.Array; | ||
import java.util.*; | ||
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. Shouldn't imported classes be listed explicitly? |
||
|
||
public class Gary { | ||
public static void main(String[] args) throws GaryException { | ||
|
||
System.out.println("Hello, i'm Gary! What's on your to do list today?\n"); | ||
Scanner sc = new Scanner(System.in); | ||
ArrayList<Task> items = new ArrayList<>(); | ||
|
||
String nxt = sc.nextLine(); | ||
|
||
while (!nxt.equals("bye")) { | ||
|
||
if (nxt.equals("list")) { | ||
Gary.printList(1, items); | ||
} else if (nxt.equals("mark")) { | ||
System.out.println("which tasks have you completed? e.g. 2 3"); | ||
String nums = sc.nextLine(); | ||
String[] first = nums.split(" "); | ||
int i = 0; | ||
for (String str : first) { | ||
items.get(Integer.parseInt(first[i]) - 1).toMark(); | ||
i++; | ||
} | ||
Gary.printList(2, items); | ||
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. I like that you enabled multi-step commands! |
||
|
||
} else if (nxt.equals("unmark")) { | ||
System.out.println("made some mistakes?"); | ||
String nums = sc.nextLine(); | ||
String[] first = nums.split(" "); | ||
int k = 0; | ||
for (String str : first) { | ||
items.get(Integer.parseInt(first[k]) - 1).toUnmark(); | ||
k++; | ||
} | ||
} else if (nxt.equals("delete")) { | ||
System.out.println("Please key in what you would like to remove in descending order!"); | ||
try { | ||
String nums = sc.nextLine(); | ||
String[] first = nums.split(" "); | ||
int k = 0; | ||
for (String str : first) { | ||
items.remove(Integer.parseInt(first[k]) - 1); | ||
k++; | ||
} | ||
Gary.printList(2, items); | ||
} catch (IndexOutOfBoundsException e) { | ||
System.out.println("Ah please enter a valid number or sequence e.g. 5 3 1"); | ||
} | ||
|
||
} else { | ||
String[] type = nxt.split(" "); | ||
String theTask = type[0]; | ||
try { | ||
if (!theTask.equals("todo") && !theTask.equals("event") && !theTask.equals("deadline")) { | ||
throw new GaryException(nxt); // invalid input | ||
} | ||
} catch (GaryException e) { | ||
e.GaryError(); | ||
} | ||
|
||
try { | ||
switch (theTask) { | ||
case "todo": | ||
items.add(new ToDo(nxt.substring(5))); | ||
break; | ||
case "event": | ||
String[] e = nxt.split("/", 5); | ||
items.add(new Event(e[0].substring(6), e[1])); | ||
break; | ||
case "deadline": | ||
String[] d = nxt.split("/", 5); | ||
items.add(new Deadlines(d[0].substring(9), d[1])); | ||
break; | ||
} | ||
} catch (StringIndexOutOfBoundsException e) { | ||
System.out.println("Ah please enter a valid description e.g. task_type name / date"); | ||
} | ||
} | ||
nxt = sc.nextLine(); // continue getting inputs | ||
} | ||
System.out.println("Bye, hope you stay productive!\n"); | ||
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. Parser is clean and easy to understand! |
||
} | ||
|
||
public static void printList(int type, ArrayList<Task> item) { | ||
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. Perhaps the variable name should be in plural form for ArrayList? |
||
if (type == 1) { | ||
System.out.println("Tasks:"); | ||
} else { | ||
System.out.println("Alright, this is your updated to do list"); | ||
} | ||
int j = 1; | ||
for (Task str : item) { | ||
System.out.printf("%d. %s\n", j, str); | ||
j++; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class GaryException extends Exception { | ||
// represent exceptions specific to Gary | ||
// int err; | ||
String msg; | ||
|
||
public GaryException(String msg) { | ||
// this.err = err; | ||
this.msg = msg; | ||
} | ||
|
||
public void GaryError() { | ||
System.out.printf("Sorry, what is %s ?\n", this.msg); | ||
} | ||
} | ||
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. Would be useful to add javadocs documentation for custom exceptions! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import java.util.*; | ||
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. Shouldn't imported classes be listed explicitly? |
||
|
||
public class Task { | ||
protected String task; | ||
protected boolean isDone; | ||
|
||
public Task(String task) { | ||
this.task = task; | ||
this.isDone = false; | ||
} | ||
|
||
public void toMark() { | ||
this.isDone = true; | ||
} | ||
|
||
public void toUnmark() { | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String done = this.isDone ? "X" : " "; | ||
return "[" + done + "] " + this.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. toString is abstracted well for Task and its children classes! |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class ToDo extends Task { | ||
|
||
public ToDo(String str) { | ||
super(str); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "T" + super.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
Hello, i'm Gary! What's on your to do list today? | ||
which tasks have you completed? e.g. 2 3 | ||
Alright, this is your updated to do list | ||
1. T[X] watch Red Notice | ||
Bye, hope you stay productive! | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
todo watch Red Notice | ||
mark | ||
1 | ||
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.
It would be good to have an access modifier for these fields. Same comment for Event.