-
Notifications
You must be signed in to change notification settings - Fork 197
[Gerald Koh Kheng Guan] iP #192
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?
Changes from 7 commits
de8ed4d
5d5cc71
bc93fd2
7d21da9
6d10d3f
444b5c0
f7d165c
25dffa2
609c4a9
544ba64
8902eae
69d4b63
959c5a4
13f7505
8a06c04
e0c6dc9
391f7bf
77ef37e
6ba8f86
f423633
bf20902
cbc2097
c9f98f4
7831692
6df56ee
f4792f0
a7d571e
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,13 @@ | ||
| 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,70 @@ | ||
| import java.util.Scanner; | ||
| public class Duke { | ||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| Methods.printGreetings(); | ||
|
|
||
| Task[] actions = new Task[100]; | ||
| int actionCounter = 0; | ||
|
|
||
| String line; | ||
| Scanner in = new Scanner(System.in); | ||
| int taskNumber; | ||
| String[] decisions; | ||
| Task toBeAdded; | ||
| String[] dates; | ||
| do { | ||
| line = in.nextLine(); | ||
| decisions = line.split(" "); | ||
| dates = line.split("/"); | ||
| switch (decisions[0]) { | ||
| case "echo": | ||
| System.out.println(Methods.findTaskDetails(line)); | ||
| break; | ||
|
|
||
| case "todo": | ||
| toBeAdded = new Todo(Methods.findTaskDetails(line)); | ||
| actions[actionCounter] = toBeAdded; | ||
| actionCounter++; | ||
| Methods.printAcknowledgement(toBeAdded,actionCounter); | ||
| break; | ||
|
|
||
| case "event": | ||
| toBeAdded = new Event(Methods.findTaskDetails(dates[0]), Methods.findTaskDetails(dates[1]), Methods.findTaskDetails(dates[2])); | ||
| actions[actionCounter] = toBeAdded; | ||
| actionCounter++; | ||
| Methods.printAcknowledgement(toBeAdded,actionCounter); | ||
| break; | ||
|
|
||
| case "deadline": | ||
| toBeAdded = new Deadline(Methods.findTaskDetails(dates[0]), Methods.findTaskDetails(dates[1])); | ||
| actions[actionCounter] = toBeAdded; | ||
| actionCounter++; | ||
| Methods.printAcknowledgement(toBeAdded,actionCounter); | ||
| break; | ||
|
|
||
| case "mark": | ||
| taskNumber = Integer.parseInt(decisions[1]) - 1; | ||
| actions[taskNumber].mark(); | ||
| Methods.printDoneMarkingTasks(actions[taskNumber]); | ||
| break; | ||
|
|
||
| case "unmark": | ||
| taskNumber = Integer.parseInt(decisions[1]) - 1; | ||
| actions[taskNumber].unmark(); | ||
| Methods.printDoneMarkingTasks(actions[taskNumber]); | ||
| break; | ||
|
|
||
| case "list": | ||
| if (actionCounter == 0) { | ||
| Methods.printEmptyList(); | ||
| continue; | ||
| } | ||
| for (int iterator = 0; iterator < actionCounter; iterator++) { | ||
| Methods.printListElement(iterator, actions[iterator]); | ||
| } | ||
| break; | ||
| } | ||
|
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 include a default branch for your switch block so in the case where your command is not caught by any of the case statements, your code will still function. 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. Good job on formatting your case statements! |
||
| } while (!decisions[0].equals("bye")); | ||
| System.out.println("That's all from me! Goodbye!"); | ||
| } | ||
| } | ||
|
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 consider how to abstract your main method into various different methods as currently it is rather lengthy (Greater than 30 LOC). |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| public class Event extends Task { | ||
|
|
||
| protected String from; | ||
| protected String to; | ||
|
|
||
| public Event(String description, String from, String to) { | ||
| super(description); | ||
| this.from = from; | ||
| this.to = to; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[E]" + super.toString() + " (from: " + from + "to: " + to + ")"; | ||
|
|
||
|
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. Remember to remove extra new lines in your code! |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import java.util.Scanner; | ||
| public class Methods { | ||
|
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. Good use on plurals to define your class! |
||
| public static void printGreetings() { | ||
| String logo = " ____ _ \n" | ||
|
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. You might want to consider declaring these variables as constants instead as they are they do not need to change. |
||
| + "| _ \\ _ _| | _____ \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. Good job on wrapping the texts! |
||
| System.out.println("Hello! Do you need anything from me?\n" | ||
| + "I have only been trained to greet, echo and list you so far.\n" | ||
| + "Once my owner is more proficient in what he does, he will give me more functions!\n" | ||
| + "Key in a number based on the function\n 1)echo \n 2)todo\n 3)mark\n 4)unmark\n 5)deadline\n 6)event\n" | ||
| + "When you wish to exit, do tell me by typing : bye"); | ||
| } | ||
| public static void print(String input) { | ||
| System.out.println(input); | ||
| } | ||
|
|
||
| public static void printEmptyList() { | ||
| System.out.println("There is nothing to list!"); | ||
| } | ||
|
|
||
| public static void printListElement(int iterator, Task action) { | ||
| Methods.print(iterator + 1 | ||
| + ")" | ||
| + action.toString()); | ||
| } | ||
| public static void printDoneMarkingTasks(Task action) { | ||
| Methods.print("Done!\n" + action.toString()); | ||
| } | ||
| public static String findTaskDetails(String line) { | ||
| return line.substring(line.indexOf(" ") + 1); | ||
| } | ||
| public static void printAcknowledgement(Task action, int actionCounter) { | ||
| System.out.println("Got it. I've added this task:\n" + action.toString() + System.lineSeparator() + "Now you have " + actionCounter + " tasks in the list."); | ||
| } | ||
| } | ||
|
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 you did a good job at making your method names simple yet descriptive. This makes it easy to follow the program flow. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| 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; | ||
| } | ||
| public String getDescription() { | ||
| return(this.description); | ||
| } | ||
| public String toString() { | ||
| return( "[" + this.getStatusIcon() + "] " + this.getDescription()); | ||
| } | ||
| } |
| 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(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
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.
When wrapping texts, remember to indent 8 spaces (or 2 tabs) from former line