-
Notifications
You must be signed in to change notification settings - Fork 197
[Liam Van] IP #199
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?
[Liam Van] IP #199
Changes from 10 commits
ab76983
66f05b6
326cf60
e77c524
2cc0131
489244b
9cc6ba3
9939b56
c8898cc
c233d69
a760d20
238fb85
acd898a
6940bc1
96b58be
804bf2e
d9dc7c1
99237ca
f9bb7fe
73543ab
cef26a2
5886c71
c12849d
eee98c8
1b6cb39
c222d8e
660cda3
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,179 @@ | ||
| package duke; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| import tasks.Task; | ||
| import tasks.Deadline; | ||
| import tasks.Event; | ||
| import tasks.Todo; | ||
|
|
||
| import dukeException.DukeException; | ||
| import dukeException.DukeIOBException; | ||
|
|
||
| public class Duke { | ||
|
|
||
| public Duke() { | ||
|
|
||
| } | ||
|
|
||
| /* | ||
| Main function that takes user input and interpets how to store and what to do with it | ||
| */ | ||
| 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. Do avoid leaving spaces like this as it goes against the Java Coding Standards |
||
| ArrayList<String> userInputs = new ArrayList<>(); | ||
| ArrayList<Task> tasks = new ArrayList<>(); | ||
| Scanner scan = new Scanner(System.in); | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
|
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 notice that you have a tendency to use magic strings and numbers. Do try to avoid that where possible, and instead use constants to set your strings/numbers. |
||
|
|
||
| greetUser(); | ||
|
|
||
| while (true) { | ||
| Task tsk = null; | ||
| String input = scan.nextLine(); | ||
| String[] splitInput = input.split(" "); | ||
|
|
||
| switch (splitInput[0]) { | ||
| case "bye": | ||
| exit(); | ||
| return; | ||
| case "todo": | ||
| try { | ||
| tsk = new Todo(splitInput[1], false); | ||
| addToList(input, userInputs); | ||
| tasks.add(tsk); | ||
| addTaskPrint(tasks, tsk); | ||
| } catch (IndexOutOfBoundsException de) { | ||
| printExceptionMsg("todo", "description of a todo cannot be empty."); | ||
| } catch (DukeException de) { | ||
|
|
||
| } | ||
|
|
||
|
|
||
| break; | ||
| case "event": | ||
| tsk = parseEvent(input); | ||
| addToList(input, userInputs); | ||
| tasks.add(tsk); | ||
| addTaskPrint(tasks, tsk); | ||
| break; | ||
| case "deadline": | ||
| tsk = parseDeadline(input); | ||
| addToList(input, userInputs); | ||
| tasks.add(tsk); | ||
| addTaskPrint(tasks, tsk); | ||
| break; | ||
| case "list": | ||
| listOut(userInputs, tasks); | ||
| break; | ||
| case "mark": | ||
| tasks.get(Integer.parseInt(splitInput[1]) - 1).mark(); | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tNice! I've marked this task as done:"); | ||
| System.out.println("\t " + tasks.get(Integer.parseInt(splitInput[1]) - 1)); | ||
| System.out.println("\t____________________________________________________________"); | ||
| break; | ||
| case "unmark": | ||
| tasks.get(Integer.parseInt(splitInput[1]) - 1).unMark(); | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tOK, I've marked this task as not done yet:"); | ||
| System.out.println("\t " + tasks.get(Integer.parseInt(splitInput[1]) - 1)); | ||
| System.out.println("\t____________________________________________________________"); | ||
| break; | ||
| default: | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-(");; | ||
| System.out.println("\t____________________________________________________________"); | ||
|
|
||
| break; | ||
| } | ||
| } | ||
| } | ||
| public static void printExceptionMsg(String task, String err) { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty."); | ||
| System.out.println("\t____________________________________________________________"); | ||
| } | ||
| public static void addTaskPrint(ArrayList<Task> tasks, Task tsk) { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tGot it. I've added this task:"); | ||
| System.out.println("\t " + tsk.toString()); | ||
| System.out.println("\tNow you have " + tasks.size() + " tasks in the list."); | ||
| System.out.println("\t____________________________________________________________"); | ||
| } | ||
| /* | ||
| This Returns the input as a Deadline object | ||
|
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. Please remove such comments as they go against the java coding standards. |
||
| */ | ||
| public static Deadline parseDeadline(String input) { | ||
| int idx = input.indexOf("/by"); | ||
| String desc = input.substring(8, idx); | ||
| String by = input.substring(idx + 3); | ||
| Deadline tsk = null; | ||
| try { | ||
| tsk = new Deadline(desc, false, by); | ||
| } catch (DukeException de) { | ||
|
|
||
| } | ||
| return tsk; | ||
| } | ||
| /* | ||
| This Returns the input as a Event object | ||
| */ | ||
| public static Event parseEvent(String input) { | ||
| int idx = input.indexOf("/from"); | ||
| int idx1 = input.indexOf("/to"); | ||
| String desc = input.substring(5, idx); | ||
| String start = input.substring(idx + 5, idx1); | ||
| String end = input.substring(idx1 + 3, input.length()); | ||
| Event tsk = null; | ||
| try { | ||
| tsk = new Event(desc, false, start, end); | ||
| } catch (DukeException de) { | ||
|
|
||
| } | ||
| return tsk; | ||
| } | ||
| /* | ||
| This Adds the input to an input array for the ability to keep track of | ||
| */ | ||
| public static void addToList(String cmd, ArrayList<String> userInputs) { | ||
| userInputs.add(cmd); | ||
| userInputs.set(userInputs.size() - 1, userInputs.size() + ". [ ] " + userInputs.get(userInputs.size() - 1)); | ||
| } | ||
| /* | ||
| This method lists out the tasks in order | ||
| */ | ||
| public static void listOut(ArrayList<String> userInputs, ArrayList<Task> tasks) { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for (int i = 0; i < tasks.size(); i++) { | ||
| System.out.println("\t" + (i + 1) + "." + tasks.get(i)); | ||
| } | ||
| System.out.println("\t____________________________________________________________"); | ||
| } | ||
| /* | ||
| Automated greet function | ||
| */ | ||
| public static void greetUser() { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tHello! I'm Duke"); | ||
| System.out.println("\tWhat can I do for you?"); | ||
| System.out.println("\t____________________________________________________________"); | ||
| } | ||
| /* | ||
| Exit message | ||
| */ | ||
| public static void exit() { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tBye. Hope to see you again soon!"); | ||
| System.out.println("\t____________________________________________________________"); | ||
|
|
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package dukeException; | ||
|
|
||
| public class DukeException extends Throwable { | ||
|
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 not to leave your exceptions empty. Perhaps you could have the corresponding error message and a method to print/return the error message? |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package dukeException; | ||
|
|
||
| public class DukeIOBException extends java.lang.ArrayIndexOutOfBoundsException { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package tasks; | ||
|
|
||
| import dukeException.DukeException; | ||
|
|
||
| public class Deadline extends Task { | ||
|
|
||
| protected String by; | ||
|
|
||
| public Deadline(String description, boolean isMark, String by) throws DukeException { | ||
| super(description, isMark); | ||
| this.by = by; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[D]" + super.toString() + "(by:" + by + ")"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package tasks; | ||
|
|
||
| import dukeException.DukeException; | ||
|
|
||
| public class Event extends Task { | ||
|
|
||
| private String start; | ||
| private String end; | ||
|
|
||
|
|
||
| public Event(String description, boolean isMark, String start, String end) throws DukeException { | ||
| super(description, isMark); | ||
| this.start = start; | ||
| this.end = end; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[E]" + super.toString() + "(from:" + this.start + "to:" + this.end + ")"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package tasks; | ||
|
|
||
| import dukeException.DukeException; | ||
|
|
||
| public class Task { | ||
| private String description; | ||
| private boolean isMark; | ||
| public Task(String inDescription, boolean isMark) throws DukeException { | ||
| if (inDescription.length() == 0) { | ||
| throw new DukeException(); | ||
| } | ||
| this.description = inDescription; | ||
| this.isMark = isMark; | ||
| } | ||
| public void mark() { | ||
| this.isMark = true; | ||
| } | ||
| public void unMark() { | ||
| this.isMark = false; | ||
| } | ||
| public String getMarked() { | ||
| if (this.isMark) { | ||
| return "[X]"; | ||
| } else { | ||
| return "[ ]"; | ||
| } | ||
| } | ||
|
|
||
| public String toString() { | ||
| return this.getMarked() + " " + this.description; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package tasks; | ||
|
|
||
| import dukeException.DukeException; | ||
|
|
||
| public class Todo extends Task { | ||
| public Todo(String description, boolean isMark) throws DukeException { | ||
|
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. Please do remove the extra space between |
||
| super(description, isMark); | ||
|
|
||
| } | ||
|
|
||
| @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.
Do consider removing empty methods, if not you could refactor some of your code into this. :)