-
Notifications
You must be signed in to change notification settings - Fork 200
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
[Tze Loong] iP #213
base: master
Are you sure you want to change the base?
[Tze Loong] iP #213
Changes from 9 commits
7558b46
dbc5dac
f808559
50aad95
312117e
98bc638
2306a2a
cb74c50
fe13d52
f5259c3
dc3b488
7b1e715
88c2683
1712749
de06295
3b1d6d4
409496b
8c09680
d44a21d
1e53d33
2b06b30
9a1c515
57076f4
b847776
c8ce553
6df5295
212cf99
7e9c93f
b624d2a
6009396
da04bb5
c7ddfbe
1ad8a59
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 Tasks { | ||
|
||
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,106 @@ | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
|
||
private static Tasks[] list_of_tasks = new Tasks[101]; | ||
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. Consider other data structures, apart from a fixed size array, to make your product more scalable, especially since we are already approaching recess week :) |
||
private static int counter = 0; | ||
|
||
public static void greet_user() { | ||
System.out.println("Hello! I'm Duke \n"); | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println(logo); | ||
System.out.println("How can i help u? \n"); | ||
} | ||
|
||
public static void print_action() { | ||
System.out.println("\n"); | ||
System.out.println("I have added this task: "); | ||
System.out.println(list_of_tasks[counter - 1].toString()); | ||
|
||
System.out.println("You now have " + counter + " tasks in the list."); | ||
} | ||
|
||
public static void Todo(String description) { | ||
Tasks t = new ToDo(description); | ||
list_of_tasks[counter] = t; | ||
counter++; | ||
print_action(); | ||
} | ||
|
||
public static void Deadline(String description, String by) { | ||
Deadline d = new Deadline(description, by); | ||
list_of_tasks[counter] = d; | ||
counter++; | ||
print_action(); | ||
} | ||
|
||
public static void Event(String description, String start, String end) { | ||
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. Avoid using constructor names of other classes as method name. It can be confusing and potential source of bug. Also, consider separate classes for adding new tasks. |
||
Event E = new Event(description, start, end); | ||
list_of_tasks[counter] = E; | ||
counter++; | ||
print_action(); | ||
} | ||
|
||
public static void List() { | ||
System.out.println("Here are all of your " + counter + " tasks: "); | ||
for (int i = 0; i < counter; i++) { | ||
System.out.println(i + 1 + "." + list_of_tasks[i].toString()); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
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. Try keeping your main method short and have a parser to deal with interpreting user commands instead |
||
greet_user(); | ||
|
||
Scanner scan = new Scanner(System.in); | ||
String input = scan.nextLine(); | ||
String[] command = input.split(" ", 2); | ||
|
||
while (!"bye".equals(input)) { | ||
switch (command[0]) { | ||
case "todo": | ||
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. Switch-case should not have different indentations. |
||
Todo(command[1]); | ||
break; | ||
case "deadline": | ||
String[] d = command[1].split("/by", 2); | ||
String d_description = d[0]; | ||
String d_by = d[1]; | ||
Deadline(d_description, d_by); | ||
break; | ||
case "event": | ||
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 consider using constants instead of strings, for example, COMMAND_EVENT instead of "event" |
||
String[] e = command[1].split("/", 3); | ||
String e_description = e[0]; | ||
String e_start = e[1]; | ||
String e_end = e[2]; | ||
Event(e_description, e_start, e_end); | ||
break; | ||
case "list": | ||
List(); | ||
break; | ||
case "mark": | ||
Integer m_index = Integer.valueOf(command[1]); | ||
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. m_index, u_index etc. might be easy for the original developer to understand but not for someone else reading it or another person taking over. Consider using clearer naming in this case. |
||
list_of_tasks[m_index - 1].markAsDone(); | ||
System.out.println("Nice! This task is completed"); | ||
System.out.println(list_of_tasks[m_index - 1].toString()); | ||
break; | ||
case "unmark": | ||
Integer u_index = Integer.valueOf(command[1]); | ||
list_of_tasks[u_index - 1].markAsUnDone(); | ||
System.out.println("Nice! This task is completed"); | ||
System.out.println(list_of_tasks[u_index - 1].toString()); | ||
break; | ||
default: | ||
System.out.println("There was an error. Please try again"); | ||
break; | ||
} | ||
input = scan.nextLine(); | ||
command = input.split(" ", 2); | ||
} | ||
System.out.println("Goodbye. Hope to see u again :) \n"); | ||
scan.close(); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Event extends Tasks { | ||
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 "[E]" + super.toString() + "(" + start + end + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public class Tasks { | ||
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 you could name this class as "Task" (singular) instead as it refers to one task |
||
|
||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Tasks(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "[X]" : "[ ]"); // mark done task with X | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void markAsUnDone() { | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getStatusIcon() + " " + description; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class ToDo extends Tasks { | ||
|
||
public ToDo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + super.toString(); | ||
} | ||
} |
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.
Consistent 4 spaces indent throughout the code, good job