-
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
[Fahim Tajwar] iP #377
base: master
Are you sure you want to change the base?
[Fahim Tajwar] iP #377
Changes from 10 commits
556af3f
7fb3c62
585628d
749cb50
b1e0b2a
37c96bf
f7de89a
1574507
22a6ad8
d62dc45
2b0a112
f41e8e9
8d23902
4e1ff5e
a388982
349a0fc
a3cb086
85f2b1f
7bf0c8d
7effb96
9b3cf3f
8a7e229
f2ccca6
57565ad
af428b8
8393433
bc50cb9
3f4922b
914347b
41b42ef
97c39aa
020b0cc
0c9f275
f3ae32d
23f3ff2
0c74c26
9244628
48cbe28
6c20142
59489b0
dcdfadf
30f927c
e8e9f16
d90ccb8
1af69e9
b0532a9
d0b8fd2
3ec344e
b1b68cc
a2106a0
fa9494c
0173c39
a531450
02c62a7
76b459f
e5a54ba
eda9529
6ac9078
1b3c45f
eee9720
c651eb9
bd2f74e
3c98b99
f330f66
f9dc729
3289ea2
e7a2ca3
f1fd6f3
503133b
e9ff01c
96cb503
1113aee
6c30c20
67b82ba
dbcd44f
ee130c6
ba43f57
3c82330
2371311
a5d30e0
5ba3415
a69ed15
d6d6a06
0ee4cbe
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 by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by: " + by + ")"; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,10 +1,122 @@ | ||||||
import java.util.*; | ||||||
|
||||||
public class Duke { | ||||||
public static void main(String[] args) { | ||||||
String logo = " ____ _ \n" | ||||||
+ "| _ \\ _ _| | _____ \n" | ||||||
+ "| | | | | | | |/ / _ \\\n" | ||||||
+ "| |_| | |_| | < __/\n" | ||||||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||||||
System.out.println("Hello from\n" + logo); | ||||||
public static void main(String[] args) { | ||||||
// String logo = " ____ _ \n" | ||||||
// + "| _ \\ _ _| | _____ \n" | ||||||
// + "| | | | | | | |/ / _ \\\n" | ||||||
// + "| |_| | |_| | < __/\n" | ||||||
// + "|____/ \\__,_|_|\\_\\___|\n"; | ||||||
// System.out.println("Hello from\n" + logo); | ||||||
|
||||||
String divider = "____________________________________________________________\n"; | ||||||
System.out.println(divider + "Hello! I'm Duke"); | ||||||
System.out.println("What can I do for you?\n" + divider); | ||||||
|
||||||
ArrayList<Task> tasks = new ArrayList<>(); | ||||||
Scanner sc = new Scanner(System.in); | ||||||
|
||||||
while(sc.hasNext()) { | ||||||
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 noticed several Java reserved words such as
Suggested change
Perhaps you could consider using IntelliJ's code cleanup feature to add these white spaces automatically. 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. Be careful of using |
||||||
String instr = sc.nextLine(); | ||||||
switch(instr) { //Single-word instructions | ||||||
case "list": //List down | ||||||
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 indentation for
Suggested change
|
||||||
System.out.println(divider + "Here are the tasks in your list:\n"); | ||||||
for(int i = 1; i <= tasks.size(); i++) { | ||||||
System.out.println(i + ". " + tasks.get(i-1)); | ||||||
} | ||||||
System.out.println(divider); | ||||||
break; | ||||||
|
||||||
case "bye": //Exit | ||||||
System.out.println(divider + "Bye. Hope to see you again soon!\n" + divider); | ||||||
return; | ||||||
|
||||||
//Other single word commands go here. | ||||||
|
||||||
default: //Instructions with arguments | ||||||
StringTokenizer tokens = new StringTokenizer(instr, " "); | ||||||
String action = tokens.nextToken(); //Splitting the action and args. | ||||||
|
||||||
String keyword = ""; //keyword = argument(s) after the action. | ||||||
while(tokens.hasMoreTokens()) { | ||||||
keyword = keyword + " " + tokens.nextToken(); | ||||||
} | ||||||
keyword = keyword.strip(); | ||||||
if(keyword.equals("")) { | ||||||
System.out.println(divider + "OOPS!!! The description of a " + action + " cannot be empty.\n" + divider); | ||||||
} | ||||||
|
||||||
switch(action) { //For instructions with argument(s). | ||||||
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 recommend against nesting |
||||||
case "add": | ||||||
tasks.add(new Task(keyword)); | ||||||
break; | ||||||
|
||||||
case "mark": | ||||||
try { | ||||||
Task t1 = tasks.get(Integer.parseInt(keyword) - 1); | ||||||
t1.mark(); | ||||||
System.out.println(divider + "Nice! I've marked this task as done:\n" + t1 + "\n" + divider); | ||||||
} catch(IndexOutOfBoundsException ioobe) { | ||||||
System.out.println("Sorry, the index number you've entered does not exist."); | ||||||
continue; | ||||||
} catch(NumberFormatException nfe) { | ||||||
System.out.println("Please enter the index number you wish to mark/unmark."); | ||||||
} | ||||||
break; | ||||||
|
||||||
case "unmark": | ||||||
try { | ||||||
Task t2 = tasks.get(Integer.parseInt(keyword) - 1); | ||||||
t2.unmark(); | ||||||
System.out.println(divider + "OK! I've marked this task as not done yet:\n" + t2 + "\n" + divider); | ||||||
} catch(IndexOutOfBoundsException ioobe) { | ||||||
System.out.println("Sorry, the index number you've entered does not exist."); | ||||||
continue; | ||||||
} catch(NumberFormatException nfe) { | ||||||
System.out.println("Please enter the index number you wish to mark/unmark."); | ||||||
} | ||||||
break; | ||||||
|
||||||
case "todo": | ||||||
tasks.add(new Todo(keyword)); | ||||||
break; | ||||||
|
||||||
case "deadline": | ||||||
String[] deadlineFinder = keyword.split(" /by "); //Split keyword into description and date, separated by "/by". | ||||||
keyword = deadlineFinder[0]; | ||||||
try { | ||||||
String deadline = deadlineFinder[1]; | ||||||
tasks.add(new Deadline(keyword, deadline)); | ||||||
} catch(IndexOutOfBoundsException ioobe) { | ||||||
System.out.println("Please define a deadline following the keyword '/by'."); | ||||||
} | ||||||
break; | ||||||
|
||||||
case "event": | ||||||
String[] startFinder = keyword.split(" /from "); //Split keyword into description and start,end. | ||||||
try{ | ||||||
String[] endFinder = startFinder[1].split(" /to "); //Split start,end into start and end. | ||||||
tasks.add(new Event(startFinder[0], endFinder[0], endFinder[1])); | ||||||
} catch(IndexOutOfBoundsException ioobe) { | ||||||
System.out.println("Please define a start time following the keyword '/from'\nand then an end time following the keyword '/to'."); | ||||||
} | ||||||
break; | ||||||
|
||||||
case "delete": | ||||||
try { | ||||||
int deleteIdx = Integer.parseInt(keyword); | ||||||
tasks.remove(deleteIdx - 1); | ||||||
} catch(NumberFormatException nfe) { | ||||||
System.out.println("Please enter the index number you wish to delete."); | ||||||
} catch(IndexOutOfBoundsException ioobe) { | ||||||
System.out.println("Sorry, the index number you've entered does not exist."); | ||||||
continue; | ||||||
} | ||||||
break; | ||||||
default: | ||||||
System.out.println(divider + "OOPS! I'm sorry, but I don't know what that means :-(\n" + divider); //For unknown action. | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
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. A lot of nested blocks. Consider abstracting away with methods within the main class. For example you can have: // in main
switch(...) {
case "todo":
addToDo(tokens);
}
// add implementation
public void addToDo(String[] tokens) {
// your implementation
} |
||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class DukeException extends Exception { | ||
DukeException(String msg) { | ||
super(msg); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Event extends Task { | ||
|
||
protected String start; | ||
protected String end; | ||
|
||
public Event(String description, String start, String end) { | ||
super(description); | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (from: " + start + " to: " + end + ")"; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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 | ||
} | ||
|
||
public void mark() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmark() { | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + this.getStatusIcon() + "] " + this.description; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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,80 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
____________________________________________________________ | ||
Hello! I'm Duke | ||
What can I do for you? | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
|
||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
|
||
1. [T][ ] wash car | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Nice! I've marked this task as done: | ||
[T][X] wash car | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
|
||
1. [T][X] wash car | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
OK! I've marked this task as not done yet: | ||
[T][ ] wash car | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
|
||
1. [T][ ] wash car | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
|
||
1. [T][ ] wash car | ||
2. [T][ ] Take out trash | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Nice! I've marked this task as done: | ||
[T][X] Take out trash | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
|
||
1. [T][ ] wash car | ||
2. [T][X] Take out trash | ||
3. [D][ ] assignment (by: Sunday 3pm) | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Nice! I've marked this task as done: | ||
[D][X] assignment (by: Sunday 3pm) | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
|
||
1. [T][ ] wash car | ||
2. [T][X] Take out trash | ||
3. [D][X] assignment (by: Sunday 3pm) | ||
____________________________________________________________ | ||
|
||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
|
||
1. [T][ ] wash car | ||
2. [T][X] Take out trash | ||
3. [D][X] assignment (by: Sunday 3pm) | ||
4. [D][ ] Celebration (from: morning to: night) | ||
____________________________________________________________ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
list | ||
todo wash car | ||
list | ||
mark 1 | ||
list | ||
unmark 1 | ||
list | ||
todo Take out trash | ||
list | ||
mark 2 | ||
deadline assignment /by Sunday 3pm | ||
list | ||
mark 3 | ||
list | ||
event Celebration /from morning /to night | ||
list |
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.
Should basic indentation be changed from 2 spaces to 4 spaces to align with the Java coding standard?