-
Notifications
You must be signed in to change notification settings - Fork 361
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
[Joshua Chiang] iP #374
base: master
Are you sure you want to change the base?
[Joshua Chiang] iP #374
Changes from 10 commits
556af3f
013bad8
ad0950e
de5b7bb
bfa99a9
29d0e64
1220c06
da609ba
07c5ecc
4e293ce
6290dbd
9392222
7a3dd94
e4ce66a
be7a1ad
58a0861
26059d0
d1feb10
452abdb
0ad8c0a
5c13de8
5034f20
170bf64
f048683
bbc1346
e54f110
52729dc
2512bc2
cd6068a
1fca158
9bdc21c
c8ed205
cad3c2d
3e877f7
74f9187
e01bc3b
a653274
365ab55
924c90e
eb8fe8d
450c3cf
e51bf46
a13eaef
46c2c30
6548a4a
0669b8b
ea7a14c
76cfd94
2275123
95c408b
0fccbda
40fb43f
1c17d2a
7df236a
40fa05e
66a099d
27afa01
84c82e3
8956679
44afac8
459d599
f247b9f
9c4569d
b625d1e
e821f98
5120053
1f263ab
1fc1c2d
f8bf218
30c2484
3c17451
3c76232
d80c1d1
556ebf7
ff2676b
d6dd838
5e4993e
81e21e4
7a7ce5c
32ab103
85405b0
6dccea8
f4e2c43
e9cf8c0
69b9fdf
7dbd28b
55c0bd2
943a308
44dca79
84d4eac
833d7f7
947eaaf
cc7736c
6c27071
8063a54
1bb04da
373f744
a782732
5d2bc03
92e92f1
794ae50
0c26416
454f236
6a3522b
9923486
187f63c
6a42181
ea8185a
bdb7de9
a0c6eb2
3374184
7760aa6
3e03af0
ca9393b
b19c87b
628e936
5696f00
74c06b1
aafbd96
1a9fd8e
e68d24a
944c732
84b8ddd
cb8c4e1
62511a4
80113b4
d71a7fb
9eb5ee2
d99d9cb
be0b09e
a822193
f086a15
8d77a7e
28f027b
56086f7
e605d95
975c908
feba5d8
60c8347
7015e14
abfe93f
b329b64
f99848d
81ff40d
e3608e4
211bdb5
fe68fca
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,15 @@ | ||
public class Deadline extends Task { | ||
protected String dueDate; | ||
|
||
public Deadline(String description, String dueDate) { | ||
super(description); | ||
this.dueDate = dueDate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.isMarked | ||
? String.format("[D][X] %1$s (by: %2$s)", this.description, this.dueDate) | ||
: String.format("[D][ ] %1$s (by: %2$s)", this.description, this.dueDate); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,10 +1,194 @@ | ||||||||||
import java.util.ArrayList; | ||||||||||
import java.util.Arrays; | ||||||||||
import java.util.List; | ||||||||||
import java.util.Scanner; | ||||||||||
|
||||||||||
public class Duke { | ||||||||||
static private final String MAKE_DEADLINE = "deadline"; | ||||||||||
static private final String MAKE_TODO = "todo"; | ||||||||||
static private final String MAKE_EVENT = "event"; | ||||||||||
static private final String DUE_DATE_FLAG = "/by "; | ||||||||||
static private final String EVENT_START_FLAG = "/from "; | ||||||||||
static private final String EVENT_END_FLAG = "/to "; | ||||||||||
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. Should the "static" keyword come before the access modifier ("private" in this case)? Namings align with the coding standard, which is great! |
||||||||||
|
||||||||||
public static boolean isNumeric(String strNum) { | ||||||||||
if (strNum == null) { | ||||||||||
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. Love your code! Tidy and clean |
||||||||||
return false; | ||||||||||
} | ||||||||||
try { | ||||||||||
double d = Double.parseDouble(strNum); | ||||||||||
} catch (NumberFormatException nfe) { | ||||||||||
return false; | ||||||||||
} | ||||||||||
return true; | ||||||||||
} | ||||||||||
|
||||||||||
public static void main(String[] args) { | ||||||||||
String logo = " ____ _ \n" | ||||||||||
+ "| _ \\ _ _| | _____ \n" | ||||||||||
+ "| | | | | | | |/ / _ \\\n" | ||||||||||
+ "| |_| | |_| | < __/\n" | ||||||||||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||||||||||
System.out.println("Hello from\n" + logo); | ||||||||||
String logo = " _____ _ _____ _\n" | ||||||||||
+ "| ___|| | _ _ | ___| | | _\n" | ||||||||||
+ "| | | | | | | | | | | |/ /\n" | ||||||||||
+ "| |___ | |___ | |__| | | |___ | \\\n" | ||||||||||
+ "|_____||_____||______| |_____| |_| \\_\\\n"; | ||||||||||
ChickenChiang marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
System.out.println(logo); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" Howdy! I'm Cluck!\n" + | ||||||||||
" What can I cluck-a-doodle-do for you?\n"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
|
||||||||||
boolean loop = true; | ||||||||||
List<Task> toDoList = new ArrayList<>(); | ||||||||||
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 a better name could be used for the
Suggested change
|
||||||||||
Scanner sc = new Scanner(System.in); | ||||||||||
|
||||||||||
while (loop) { | ||||||||||
String input = sc.nextLine(); | ||||||||||
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. Should we add a sc.close() at the end |
||||||||||
String[] words = input.split(" "); | ||||||||||
|
||||||||||
switch (words[0]) { | ||||||||||
case "bye": | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" Buh-cluck, see ya!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
loop = false; | ||||||||||
break; | ||||||||||
|
||||||||||
case "list": | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" Here are the tasks in your list:"); | ||||||||||
for (int i = 0; i < toDoList.size(); i++) { | ||||||||||
System.out.println(" " + (i + 1) + ": " + toDoList.get(i).toString()); | ||||||||||
} | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
break; | ||||||||||
|
||||||||||
case "mark": | ||||||||||
if (words.length == 1) { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" Mucka blucka - Buh cluck! Which task do you wanna mark? "); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} | ||||||||||
else if (isNumeric(words[1])) { | ||||||||||
Integer itemNumber = Integer.parseInt(words[1]); | ||||||||||
if (itemNumber > toDoList.size() || itemNumber <= 0) { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" That's not...? In the list...? Buh caw?"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} else { | ||||||||||
toDoList.get(itemNumber - 1).mark(); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(String.format(" Marked it! Cluck-a-doodle-done!\n %s", toDoList.get(itemNumber - 1).toString())); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} | ||||||||||
} else { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" Ya gotta give me a working number, bucko!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} | ||||||||||
break; | ||||||||||
|
||||||||||
case "unmark": | ||||||||||
if (words.length == 1) { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" Which task do you wanna unmark? Muckah buck!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} else if (isNumeric(words[1])) { | ||||||||||
Integer itemNumber = Integer.parseInt(words[1]); | ||||||||||
if (itemNumber > toDoList.size() || itemNumber <= 0) { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" That's not...? In the list...? Buh caw?"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} else { | ||||||||||
toDoList.get(itemNumber - 1).unmark(); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(String.format(" Unmarked it! Cluckiddy cluck!\n %s", toDoList.get(itemNumber - 1).toString())); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} | ||||||||||
} else { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" Ya gotta give me a working number, bucko!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} | ||||||||||
break; | ||||||||||
|
||||||||||
case MAKE_TODO: | ||||||||||
Task newTodo = new ToDo(input.substring(5)); | ||||||||||
toDoList.add(newTodo); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" added todo: \n " + newTodo.toString()); | ||||||||||
System.out.println(" Now there's " + toDoList.size() + " items in your list!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
break; | ||||||||||
|
||||||||||
case MAKE_DEADLINE: | ||||||||||
String body = input.substring(9); | ||||||||||
if (body.contains(DUE_DATE_FLAG)) { | ||||||||||
String[] fields = body.split(DUE_DATE_FLAG); | ||||||||||
String description = fields[0]; | ||||||||||
String dueDate = fields[1]; | ||||||||||
Task currDeadline = new Deadline(description, dueDate); | ||||||||||
toDoList.add(currDeadline); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" added deadline: " + currDeadline.toString()); | ||||||||||
System.out.println(" Now there's " + toDoList.size() + " items in your list!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
break; | ||||||||||
} | ||||||||||
|
||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" You're missing the '/by' flag, bucko!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
break; | ||||||||||
|
||||||||||
case MAKE_EVENT: | ||||||||||
String substring = input.substring(6); | ||||||||||
if (substring.contains(EVENT_START_FLAG) && substring.contains(EVENT_END_FLAG)) { | ||||||||||
String[] fields = substring.split("/\\w{2,4}\\s"); | ||||||||||
System.out.println(Arrays.toString(fields)); | ||||||||||
Task currEvent = new Event(fields[0], fields[1], fields[2]); | ||||||||||
toDoList.add(currEvent); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" added event: " + currEvent.toString()); | ||||||||||
System.out.println(" Now there's " + toDoList.size() + " items in your list!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
break; | ||||||||||
} | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" You're missing the either the '/from' or '/to' flag, or both! Buhcock!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
break; | ||||||||||
|
||||||||||
case "delete": | ||||||||||
if (words.length == 1) { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" Mucka blucka - Buh cluck! Which task do you wanna delete? "); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} | ||||||||||
else if (isNumeric(words[1])) { | ||||||||||
Integer itemNumber = Integer.parseInt(words[1]); | ||||||||||
if (itemNumber > toDoList.size() || itemNumber <= 0) { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" That's not...? In the list...? Buh caw?"); | ||||||||||
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. Interesting and Creative ui design |
||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} else { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(String.format(" Buh cuck! Removed the following:\n %s", toDoList.get(itemNumber - 1).toString())); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
toDoList.remove(itemNumber - 1); | ||||||||||
} | ||||||||||
} else { | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" Ya gotta give me a working number, bucko!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
} | ||||||||||
break; | ||||||||||
|
||||||||||
|
||||||||||
default: | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
System.out.println(" You gotta give me a command!"); | ||||||||||
System.out.println(" ____________________________________________________________"); | ||||||||||
|
||||||||||
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 remove unnecessary white spaces between lines of code, such as within the switch statement? So that the format is standardised. This applies to some parts above too. |
||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Event extends Task { | ||
protected String startTime; | ||
protected String endTime; | ||
|
||
public Event(String description, String startTime, String endTime) { | ||
super(description); | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return this.isMarked | ||
? String.format("[E][X] %1$s (from:%2$s to:%3$s)", this.description, this.startTime, this.endTime) | ||
: String.format("[E][ ] %1$s (from:%2$s to:%3$s)", this.description, this.startTime, this.endTime); | ||
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. Similar to the comment under Deadline, perhaps this could make use of the |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
public class Task { | ||
protected String description; // name of the task | ||
protected Boolean isMarked; // whether task is done or not | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isMarked = false; | ||
} | ||
public void mark() { | ||
this.isMarked = true; | ||
} | ||
|
||
public void unmark() { | ||
this.isMarked = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.isMarked | ||
? String.format("[X] %s", this.description) | ||
: String.format("[ ] %s", this.description); | ||
} | ||
|
||
} |
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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
_____ _ _____ _ | ||
| ___|| | _ _ | ___| | | _ | ||
| | | | | | | | | | | |/ / | ||
| |___ | |___ | |__| | | |___ | \ | ||
|_____||_____||______| |_____| |_| \_\ | ||
|
||
____________________________________________________________ | ||
Howdy! I'm Cluck! | ||
What can I cluck-a-doodle-do for you? | ||
|
||
____________________________________________________________ | ||
____________________________________________________________ | ||
added deadline: [D][ ] Eat cookies (by: tonight) | ||
Now there's 1 items in your list! | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Buh-cluck, see ya! | ||
____________________________________________________________ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
deadline Eat cookies /by tonight | ||
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.
Could this method make use of abstraction so that the
toString()
method in the parent class Task could be used here? Then, you would only need to add the correct task icon ("D" for Deadline here) and the due date, making it easier to read.