-
Notifications
You must be signed in to change notification settings - Fork 223
[Jared Lim] iP #276
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
base: master
Are you sure you want to change the base?
[Jared Lim] iP #276
Changes from 7 commits
d3163e8
d4a6722
fe3ca81
5039c1a
da14f03
0de7bcb
5da5f47
77d1af0
18fefbf
c8a2318
1304374
4f24e1a
1840dd9
0ea2605
32edbd5
14600d2
03647c1
e7ef799
e1e5628
51aa8fe
bf88b10
0f29c67
f81b02a
507b9d7
677fc36
9949574
1b8b269
e874003
95b3b38
d6ece15
7207a74
518584e
b4d202a
64f4838
c110de9
23b0d4c
a8522c6
7af6082
b07b0a0
5f828d2
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 |
|---|---|---|
| @@ -1,20 +1,25 @@ | ||
| # User Guide | ||
|
|
||
| JDK 11 | ||
| ## Features | ||
|
|
||
| ### Feature 1 | ||
| Description of feature. | ||
| Bot that takes in a list of actions to do and stores it in a list. Tasks that are | ||
| done are marked as done. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### `Keyword` - Describe action | ||
|
|
||
| Describe action and its outcome. | ||
|
|
||
| Basic todo list. | ||
| Example of usage: | ||
|
|
||
| `keyword (optional arguments)` | ||
| `Read book` | ||
|
|
||
| Expected outcome: | ||
|
|
||
| Retrieving the list by typing the string list as input will give: | ||
| Here are the tasks in your list: | ||
| 1.[] Read book | ||
|
|
||
| `outcome` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| public class Deadline extends Task { | ||
|
|
||
| Deadline(String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| Deadline(String description, String eventDate) { | ||
| super(description, eventDate); | ||
| } | ||
|
|
||
| @Override | ||
| public String getTaskType() { | ||
| return "D"; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[%s][%s] %s(by:%s)", this.getTaskType(), | ||
| this.getStatusIcon(), this.getDescription(), this.getEventDate()); | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,135 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| /** | ||
| * Driver class that takes in input and performs certain functions based on input. | ||
| */ | ||
| public class Duke { | ||
|
|
||
| protected static ArrayList<Task> taskList = new ArrayList<>(); | ||
|
|
||
| /** | ||
| * Main class to take in user input. | ||
| * @param args Filler | ||
|
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 more meaningful name for @param could be possibly replaced here |
||
| */ | ||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| Scanner sc = new Scanner(System.in); | ||
|
|
||
| String command = "Hello"; | ||
|
|
||
| while (!command.equalsIgnoreCase("bye")) { | ||
| if (command.equals("Hello")) { | ||
| System.out.println("Hello! I'm Duke"); | ||
| System.out.println("What can I do for you?"); | ||
| } else if (command.equals("list")) { | ||
| enumerateTasks(); | ||
| } else if (command.startsWith("done")) { | ||
| String[] delString = command.split("\\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. delString is not a very intuitive variable name, maybe you could make it more specific? |
||
| markAsDone(Integer.parseInt(delString[1])); | ||
| } else if (command.startsWith("todo")) { | ||
| try { | ||
| Todo currentTask = new Todo(command.substring(5)); | ||
| addToTasks(currentTask); | ||
| logTask(currentTask); | ||
| } catch (StringIndexOutOfBoundsException indexError) { | ||
| System.out.println("☹ OOPS!!! The description of a todo cannot be empty."); | ||
| } | ||
|
|
||
| } else if (command.startsWith("event")) { | ||
| try { | ||
| String[] splitString = command.split("/at"); | ||
| String eventDesc = splitString[0]; | ||
| String eventDate = splitString[1]; | ||
| Event currentTask = new Event(eventDesc.substring(6), eventDate); | ||
| addToTasks(currentTask); | ||
| logTask(currentTask); | ||
| } catch (ArrayIndexOutOfBoundsException | StringIndexOutOfBoundsException indexError) { | ||
| System.out.println("☹ OOPS!!! The description of an event cannot " + | ||
| "be empty."); | ||
| } | ||
| } else if (command.startsWith("deadline")) { | ||
| try { | ||
| String[] splitString = command.split("/by"); | ||
| String eventDesc = splitString[0]; | ||
| String eventDate = splitString[1]; | ||
| Deadline currentTask = new Deadline(eventDesc.substring(9), eventDate); | ||
| addToTasks(currentTask); | ||
| logTask(currentTask); | ||
| } catch (ArrayIndexOutOfBoundsException | StringIndexOutOfBoundsException indexError) { | ||
| System.out.println("☹ OOPS!!! The description of a deadline " + | ||
| "cannot be empty."); | ||
| } | ||
| } else if (command.startsWith("delete")) { | ||
| String[] splitString = command.split("\\s+"); | ||
| removeTask(Integer.parseInt(splitString[1])); | ||
| } else { | ||
| // Command is not recognized | ||
| System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
| } | ||
|
|
||
| command = sc.nextLine(); | ||
|
|
||
| } | ||
|
|
||
| System.out.println("Bye. Hope to see you again soon!"); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Prints the statements showing this task has been added to list. | ||
| * @param currentTask Current task. | ||
| */ | ||
| protected static void logTask(Task currentTask) { | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(currentTask); | ||
| System.out.println(String.format("Now you have %d tasks in the list" | ||
| , taskList.size())); | ||
| } | ||
|
|
||
| /** | ||
| * Adds current task to list of tasks. | ||
| * @param currentTask Current task. | ||
| */ | ||
| protected static void addToTasks(Task currentTask) { | ||
| taskList.add(currentTask); | ||
| } | ||
|
|
||
| /** | ||
| * Enumerates all tasks in the lis using 1-based indexing. | ||
|
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. Minor typo for "list" |
||
| */ | ||
| protected static void enumerateTasks() { | ||
| System.out.println("Here are the tasks in your list:"); | ||
| int counter = 1; | ||
| for (Task eachTask : taskList) { | ||
| System.out.println(String.format("%d. %s", counter, eachTask)); | ||
| counter++; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Marks task as done based on 1-based indexing. | ||
| * @param index Given index of task | ||
| */ | ||
| protected static void markAsDone(int index) { | ||
| // Retrieving task | ||
| Task givenTask = taskList.get(index - 1); | ||
| givenTask.markAsDone(); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| System.out.println(String.format(" [%s][%s] %s", | ||
| givenTask.getTaskType(), givenTask.getStatusIcon(), | ||
| givenTask.getDescription())); | ||
| } | ||
|
|
||
| /** | ||
| * Removes respective task in the list (1-based indexing). | ||
| * @param index Index of task to remove | ||
| */ | ||
| protected static void removeTask(int index) { | ||
| Task removedTask = taskList.remove(index - 1); | ||
| System.out.println("Noted. I've removed this task:"); | ||
| System.out.println(" " + removedTask); | ||
| System.out.println(String.format("Now you have %d tasks in your list.", | ||
| taskList.size())); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| public class Event extends Task { | ||
|
|
||
| /** | ||
| * Main Constructor. | ||
| * @param description Description of given task. | ||
| */ | ||
| Event(String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| /** | ||
| * Overriden constructor to account for deadline and events that have timestamps. | ||
|
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. Not too sure if "Overriden" is the appropriate term here. I think "Overloaded constructor" may be more appropriate. 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 think the term you meant to use might be "overloaded" instead |
||
| * @param description Description of given task. | ||
| * @param eventDate Timestamp of given task. | ||
| */ | ||
| Event(String description, String eventDate) { | ||
| super(description, eventDate); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieving the given task type. | ||
| * @return String giving the task type, in this case E. | ||
| */ | ||
| @Override | ||
| public String getTaskType() { | ||
| return "E"; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[%s][%s] %s(at:%s)", this.getTaskType(), | ||
| this.getStatusIcon(), this.getDescription(), this.getEventDate()); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| public class Task { | ||
|
|
||
| protected String description; | ||
| protected String eventDate; | ||
| protected boolean isDone; | ||
|
|
||
| enum Level { | ||
| low, | ||
| average, | ||
| high | ||
|
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 think that constants in enum should be in all uppercase, eg "LOW", "AVERAGE" and "HIGH" |
||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Main constructor that accepts a description of the task, and by default | ||
| * assigns a false value to the undone task. | ||
| * @param description Description of task | ||
| */ | ||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| this.eventDate = ""; | ||
| } | ||
|
|
||
| /** | ||
| * Overriden method to mark a task as done. | ||
|
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. Did you mean "Overloaded" here as well? I've noticed it in a few other places. Otherwise, as the other reviewer mentioned, overridden methods should tagged with "@OverRide" |
||
| * @param description Description of method | ||
| * @param eventDate Boolean flag indicating whether task is done | ||
| */ | ||
| public Task(String description, String eventDate) { | ||
|
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. Might be a good idea to add "@OverRide" tag if this method is truly overriden |
||
| this.description = description; | ||
| this.eventDate = eventDate; | ||
| } | ||
|
|
||
| public String getTaskType() { | ||
| return ""; | ||
| }; | ||
|
|
||
| public String getStatusIcon() { | ||
| return isDone ? "X" : ""; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return this.description; | ||
| } | ||
|
|
||
| public String getEventDate() { | ||
| return this.eventDate; | ||
| } | ||
|
|
||
| public void markAsDone() { | ||
| this.isDone = true; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| public class Todo extends Task { | ||
|
|
||
| /** | ||
| * Main constructor. | ||
| * @param description Description of task. | ||
| */ | ||
| Todo(String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| /** | ||
| * Getter method that retrieves the type of the task. | ||
| * @return String representing task type. | ||
| */ | ||
| @Override | ||
| public String getTaskType() { | ||
| return "T"; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[%s][%s] %s ", this.getTaskType(), | ||
| this.getStatusIcon(), this.getDescription()); | ||
| } | ||
| } |
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.
this class is rather long, perhaps you could consider abstracting the methods out?