-
Notifications
You must be signed in to change notification settings - Fork 76
[rohitcube] iP #86
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?
[rohitcube] iP #86
Changes from 2 commits
1d65904
102f25f
31650d6
3b2adcc
76a133a
fb4c7e8
046aa40
6d3621e
7d71e38
47c89fa
2ca1a03
2840b04
d9e74d0
22e6d32
a185c4a
d46612a
a4fd5f6
afbf41f
841f65c
3731fe1
1552e4d
f26d5a3
4129c36
7a801e3
c36c6f3
afbb48e
e9f3fd3
cdec293
d71f127
7a861a7
a049895
35b3563
9cbbef5
372929a
455325c
6924d30
d615630
2254701
63815fe
a25d92c
b41095c
25bd15c
98e22e3
6484d32
d81536c
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,157 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Dukey { | ||
| public static void main(String[] args) { | ||
| ArrayList<Task> tasks = new ArrayList<>(); | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| String line = "------------------------"; | ||
|
|
||
| System.out.println(logo); | ||
| System.out.println("User"); | ||
| System.out.println("ToDos: tasks without any date/time attached to it e.g., visit new theme park"); | ||
| System.out.println("Deadlines: tasks that need to be done before a specific date/time e.g., submit report by 11/10/2019 5pm"); | ||
|
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 splitting this line into shorter chunks. |
||
| System.out.println("Events: tasks that start at a specific date/time and ends at a specific date/time"); | ||
|
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 incorporating these lines with the logo to avoid repeating "System.out.println". |
||
|
|
||
|
|
||
| System.out.println(line); | ||
|
|
||
| while (true) { | ||
| String userInput = scanner.nextLine(); | ||
|
|
||
| if (userInput.equals("bye")) { | ||
| System.out.println(line); | ||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| break; | ||
| } else if (userInput.equals("list")) { | ||
| System.out.println(line); | ||
| if (tasks.isEmpty()) { | ||
| System.out.println("No tasks in the list."); | ||
| } else { | ||
| for (int i = 0; i < tasks.size(); i++) { | ||
| System.out.println((i + 1) + "." + tasks.get(i)); | ||
| } | ||
| } | ||
| } else if (userInput.startsWith("deadline ")) { | ||
| String[] parts = userInput.split("/by"); | ||
| String description = parts[0].substring(9).trim(); | ||
| String by = parts[1].trim(); | ||
| tasks.add(new Deadline(description, by)); | ||
| System.out.println(line); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + tasks.get(tasks.size() - 1)); | ||
| System.out.println("Now you have " + tasks.size() + " 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. Consider adding whitespaces to improve readability. |
||
| } else if (userInput.startsWith("event ")) { | ||
| String[] parts = userInput.split("/from | /to "); | ||
| String description = parts[0].substring(6).trim(); | ||
| String from = parts[1].trim(); | ||
| String to = parts[2].trim(); | ||
| tasks.add(new Event(description, from, to)); | ||
| System.out.println(line); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + tasks.get(tasks.size() - 1)); | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| } else if (userInput.startsWith("mark ")) { | ||
| int taskIndex = Integer.parseInt(userInput.split(" ")[1]) - 1; | ||
| if (taskIndex >= 0 && taskIndex < tasks.size()) { | ||
| tasks.get(taskIndex).markAsDone(); | ||
| System.out.println(line); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| System.out.println(" " + tasks.get(taskIndex)); | ||
| } else { | ||
| System.out.println(line); | ||
| System.out.println("Invalid task index."); | ||
|
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 to avoid arrowhead style convention. Perhaps you could have the marking and unmarking of task as a separate method. |
||
| } | ||
| } else if (userInput.startsWith("unmark ")) { | ||
| int taskIndex = Integer.parseInt(userInput.split(" ")[1]) - 1; | ||
| if (taskIndex >= 0 && taskIndex < tasks.size()) { | ||
| tasks.get(taskIndex).markAsNotDone(); | ||
| System.out.println(line); | ||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| System.out.println(" " + tasks.get(taskIndex)); | ||
| } else { | ||
| System.out.println(line); | ||
| System.out.println("Invalid task index."); | ||
| } | ||
| } else { | ||
| tasks.add(new Todo(userInput)); | ||
| System.out.println(line); | ||
| System.out.println("added: " + userInput); | ||
| } | ||
|
|
||
|
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. Any reason why you chose nested loops? |
||
| System.out.println(line); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class Task { | ||
|
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 should probably store the different classes in different files |
||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public void markAsDone() { | ||
| this.isDone = true; | ||
| } | ||
|
|
||
| public void markAsNotDone() { | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "[X]" : "[ ]"); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return getStatusIcon() + " " + description; | ||
| } | ||
| } | ||
|
|
||
| class Todo extends Task { | ||
| public Todo(String description) { | ||
| super(description); | ||
| } | ||
| } | ||
|
|
||
| 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 + ")"; | ||
| } | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
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.
Avoid long methods - could consider having different methods outside of the main method