-
Notifications
You must be signed in to change notification settings - Fork 267
[Wee Heng] IP #312
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?
[Wee Heng] IP #312
Changes from 7 commits
d839859
6a815ae
a716a9b
bb75b50
8e19494
b38e28d
fafdd62
eb04bc7
74a00d1
738ca50
a2ce70c
3f0f903
e6993ef
7f7c12f
39e0e6f
12cc23e
5aef82a
6925a3a
53d55f8
5ecd726
c910dac
c3ab2f1
0ccd1dc
788eebd
cef55d4
2cccc29
299caf5
8b673af
60c99d4
8c11904
60aedd2
7812b25
1fc28b2
75e98b3
eb1d240
81ef77c
ee58544
f9b1f09
66a2967
3b45581
348dc72
6aa3f90
fdc06cf
0ea16b8
d1cc88c
ad7f24e
95a600b
42acf6d
8b5e894
fdd2bc2
e187739
1467de4
ace9d19
bc87403
d830809
5b8d45b
4ac0813
11ca41c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,153 @@ | ||||||
| package duke; | ||||||
|
|
||||||
| import duke.exceptions.DukeInvalidArgumentException; | ||||||
| import duke.tasks.*; | ||||||
| import java.util.Scanner; | ||||||
| import java.util.ArrayList; | ||||||
|
|
||||||
| public class Duke { | ||||||
|
|
||||||
| private static ArrayList<Task> taskList; | ||||||
| private static Scanner getUserInput; | ||||||
|
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. getUserInput sounds like a method name. Perhaps consider changing it to
Suggested change
|
||||||
|
|
||||||
| private static void initialize(){ | ||||||
| taskList = new ArrayList<Task>(); | ||||||
| getUserInput = new Scanner(System.in); | ||||||
| } | ||||||
|
|
||||||
| public static void displayTaskList() { | ||||||
| if (taskList.isEmpty()) { | ||||||
| System.out.println("Your current task list is empty"); | ||||||
| return; | ||||||
| } | ||||||
| int taskCounter = 1; | ||||||
| System.out.println("These are the current tasks in your list:"); | ||||||
| for(Task task:taskList) { | ||||||
| System.out.printf("%d. %s \n", taskCounter, task.toString()); | ||||||
| taskCounter++; | ||||||
| } | ||||||
| } | ||||||
|
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 can use a TaskList object to separate out each user's task lists and bundle away all related methods like displaying/adding/removing to the list? |
||||||
|
|
||||||
| public static void displayTaskAdd(Task addedTask){ | ||||||
| System.out.println("This task has been added as requested:"); | ||||||
| System.out.println(addedTask.toString()); | ||||||
| System.out.printf("You now have %d item(s) in your list\n", taskList.size()); | ||||||
| } | ||||||
|
|
||||||
| public static void displayTaskDelete(Task deletedTask){ | ||||||
| System.out.println("As you wish. The following task has been removed"); | ||||||
| System.out.println(deletedTask.toString()); | ||||||
| System.out.printf("You now have %d item(s) in your list\n", taskList.size()); | ||||||
| } | ||||||
|
|
||||||
| public static String[] parseArguments(String[] arguments) throws DukeInvalidArgumentException { | ||||||
| if (arguments.length < 2) { | ||||||
| throw new DukeInvalidArgumentException("There appears to be invalid arguments"); | ||||||
| } | ||||||
|
|
||||||
| return arguments[1].split(" /([Aa][Tt]|[Bb][Yy]) ", 2); | ||||||
| } | ||||||
|
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. Maybe have some JavaDoc comments to explain non-trivial public methods? |
||||||
|
|
||||||
| public static void commandProcessor() { | ||||||
| String userInput = getUserInput.nextLine(); | ||||||
| String[] parsedUserInput = userInput.split(" ", 2); | ||||||
| switch (parsedUserInput[0].toLowerCase()) { | ||||||
| case "" : | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| case "bye": | ||||||
| System.out.println("Till we meet again"); | ||||||
| break; | ||||||
| case "list": | ||||||
| displayTaskList(); | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| case "mark": | ||||||
| int taskToMarkNumber = Integer.parseInt(parsedUserInput[1]); | ||||||
| if (taskToMarkNumber > taskList.size()) { | ||||||
| System.out.println("I am afraid that's an invalid task! Please check your task number"); | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| } | ||||||
| Task taskToMark = taskList.get(taskToMarkNumber - 1); | ||||||
| taskToMark.markAsDone(); | ||||||
| System.out.println("Duly noted. The following task has been marked 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. maybe can add a method displayMark for the print message as what you did earlier 👍 |
||||||
| System.out.println(taskToMark.toString()); | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| case "unmark": | ||||||
| int taskToUnmarkNumber = Integer.parseInt(parsedUserInput[1]); | ||||||
| if (taskToUnmarkNumber > taskList.size()) { | ||||||
| System.out.println("I am afraid that's an invalid task! Please check your task number"); | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| } | ||||||
| Task taskToUnmark = taskList.get(taskToUnmarkNumber - 1); | ||||||
| taskToUnmark.markAsNotDone(); | ||||||
| System.out.println("Very well. The following task has been marked as undone"); | ||||||
|
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. same as above displayUnmark |
||||||
| System.out.println(taskToUnmark.toString()); | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| case "todo": | ||||||
| try { | ||||||
| String[] parsedArguments = parseArguments(parsedUserInput); | ||||||
| Todo newTodo = new Todo(parsedArguments[0]); | ||||||
| taskList.add(newTodo); | ||||||
| displayTaskAdd(newTodo); | ||||||
| } catch (DukeInvalidArgumentException e) { | ||||||
| System.out.println(e.getMessage()); | ||||||
| } | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| case "deadline": | ||||||
| try { | ||||||
| String[] parsedArguments = parseArguments(parsedUserInput); | ||||||
| Deadline newDeadline = new Deadline(parsedArguments[0], parsedArguments[1]); | ||||||
| taskList.add(newDeadline); | ||||||
| displayTaskAdd(newDeadline); | ||||||
| } catch (DukeInvalidArgumentException e) { | ||||||
| System.out.println(e.getMessage()); | ||||||
| } | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| case "event": | ||||||
| try { | ||||||
| String[] parsedArguments = parseArguments(parsedUserInput); | ||||||
| Event newEvent = new Event(parsedArguments[0], parsedArguments[1]); | ||||||
| taskList.add(newEvent); | ||||||
| displayTaskAdd(newEvent); | ||||||
| } catch (DukeInvalidArgumentException e) { | ||||||
| System.out.println(e.getMessage()); | ||||||
| } | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| case "delete": | ||||||
| int taskToDeleteNumber = Integer.parseInt(parsedUserInput[1]); | ||||||
| if (taskToDeleteNumber > taskList.size()) { | ||||||
| System.out.println("I am afraid that's an invalid task! Please check your task number"); | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| } | ||||||
| Task taskToDelete = taskList.get(taskToDeleteNumber - 1); | ||||||
| taskList.remove(taskToDeleteNumber - 1); | ||||||
| displayTaskDelete(taskToDelete); | ||||||
| commandProcessor(); | ||||||
| break; | ||||||
| default: | ||||||
| System.out.println("I am unable to comprehend your request. Please try again"); | ||||||
| commandProcessor(); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public static void main(String[] args) { | ||||||
| String logo = " ____ _ \n" | ||||||
| + "| _ \\ _ _| | _____ \n" | ||||||
| + "| | | | | | | |/ / _ \\\n" | ||||||
| + "| |_| | |_| | < __/\n" | ||||||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||||||
| System.out.println("Hello from\n" + logo); | ||||||
| System.out.println("How may I assist you?"); | ||||||
| initialize(); | ||||||
| commandProcessor(); | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package duke.exceptions; | ||
|
|
||
| public class DukeException extends Exception{ | ||
| public DukeException(String message) { | ||
| super(message); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package duke.exceptions; | ||
|
|
||
| public class DukeInvalidArgumentException extends DukeException{ | ||
| public DukeInvalidArgumentException(String message) { | ||
| super(message); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package duke.tasks; | ||
|
|
||
| public class Deadline extends Task{ | ||
|
|
||
| private String date; | ||
|
|
||
| public Deadline(String content, String date) { | ||
| super(content); | ||
| this.date = date; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[D]%s (by: %s)", super.toString(), this.date); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package duke.tasks; | ||
|
|
||
| public class Event extends Task{ | ||
|
|
||
| private String date; | ||
|
|
||
| public Event(String content, String date) { | ||
| super(content); | ||
| this.date = date; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[E]%s (at: %s)", super.toString(), this.date); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||
| package duke.tasks; | ||||||
|
|
||||||
| public class Task { | ||||||
| String content; | ||||||
| boolean markedDone = false; | ||||||
|
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. boolean var can be named as isDone 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.
Suggested change
|
||||||
|
|
||||||
| public Task(String content) { | ||||||
| this.content = content; | ||||||
| } | ||||||
|
|
||||||
| public void markAsDone() { | ||||||
| this.markedDone = true; | ||||||
| } | ||||||
|
|
||||||
| public void markAsNotDone() { | ||||||
| this.markedDone = false; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public String toString() { | ||||||
| return "[" + (this.markedDone ? "X" : " ") + "] " + this.content; | ||||||
| } | ||||||
|
|
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package duke.tasks; | ||
|
|
||
| public class Todo extends Task{ | ||
| public Todo(String content) { | ||
| super(content); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[T]%s", super.toString()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| list | ||
| todo borrow book | ||
| deadline return book /by sunday | ||
| event project meeting /at Mon 2-4pm | ||
| 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.
Perhaps list all imported classes explicitly?