-
Notifications
You must be signed in to change notification settings - Fork 197
[Ahmish Nair] iP #179
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?
[Ahmish Nair] iP #179
Changes from 3 commits
be1aea7
ac3fd91
eae18af
7f125b2
e41c889
5e94384
045faf9
3a8a228
609b54e
cad0fac
232100a
3ab61fa
bd4a80f
1dcbad6
8529699
92f2716
fc243aa
640a331
f288612
38bf278
1abbbe7
71c6b7e
e7a053a
181fb6a
1964165
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,14 @@ | ||
| public class Deadline extends Task { | ||
| private String by; | ||
| private String description; | ||
|
|
||
| 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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| public class Event extends Task { | ||
| private String from; | ||
| private String to; | ||
| private String description; | ||
|
|
||
| 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 + ")"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| public class Task { | ||
| private String description; | ||
| private boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public void setDescription(String description) { | ||
| this.description = description; | ||
| } | ||
|
|
||
| public boolean getIsDone() { | ||
| return isDone; | ||
| } | ||
|
|
||
| public void setIsDone(boolean isDone) { | ||
| this.isDone = isDone; | ||
| } | ||
|
|
||
| public String status(){ | ||
| return isDone ? "[X]" : "[ ]"; | ||
| } | ||
|
|
||
| public String toString(){ | ||
| return status() + " " + getDescription(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| public class TaskManager { | ||
| private Task[] tasks; | ||
| private int taskCount; | ||
|
|
||
| public TaskManager(){ | ||
| tasks = new Task[100]; | ||
| taskCount = 0; | ||
|
||
| } | ||
|
|
||
| public void addTask(Task t) { | ||
| tasks[taskCount] = t; | ||
| taskCount++; | ||
| System.out.println("Got it. I've added this task:\n" + t.toString()); | ||
| } | ||
|
|
||
| public void mark(int index) { | ||
| tasks[index].setIsDone(true); | ||
| System.out.println("Nice! I've marked this task as done:\n" + tasks[index].toString()); | ||
| } | ||
|
|
||
| public void unmark(int index) { | ||
| tasks[index].setIsDone(false); | ||
| System.out.println("OK, I've marked this task as not done yet:\n" + tasks[index].toString()); | ||
| } | ||
|
|
||
| public void listTask() { | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for (int i = 0; i < taskCount; i++) { | ||
| System.out.println((i + 1) + "." + tasks[i].toString()); | ||
| } | ||
| } | ||
| } | ||
| 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(); | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class chatbot { | ||
| public static void main(String[] args) { | ||
| Scanner in = new Scanner(System.in); | ||
| TaskManager taskManager = new TaskManager(); | ||
|
||
| System.out.print("Hello! I'm juan\n" + "What can I do for you?\n"); | ||
|
|
||
|
|
||
| while (true) { | ||
| String input = in.nextLine(); | ||
| if (input.equalsIgnoreCase("bye")) { | ||
| System.out.print("Bye. Hope to see you again soon!"); | ||
| break; | ||
| } else if (input.equalsIgnoreCase("list")) { | ||
| taskManager.listTask(); | ||
| }else if (input.startsWith("mark ")) { | ||
| int index = Integer.parseInt(input.substring(5)) - 1; | ||
| taskManager.mark(index); | ||
| } else if (input.startsWith("unmark ")) { | ||
| int index = Integer.parseInt(input.substring(7)) - 1; | ||
|
||
| taskManager.unmark(index); | ||
| } else if(input.startsWith("todo")) { | ||
| Todo todo = new Todo(input.substring(5)); | ||
| taskManager.addTask(todo); | ||
| } else if(input.startsWith("deadline")) { | ||
| String[] parts = input.substring(9).split("/by"); | ||
| String description = parts[0].trim(); | ||
| String by = parts[1].trim(); | ||
| Deadline deadline = new Deadline(description, by); | ||
| taskManager.addTask(deadline); | ||
| } else if(input.startsWith("event")) { | ||
| String[] parts = input.substring(6).split("/from|/to"); | ||
| String description = parts[0].trim(); | ||
| String from = parts[1].trim(); | ||
| String to = parts[2].trim(); | ||
|
||
| Event event = new Event(description, from, to); | ||
| taskManager.addTask(event); | ||
| } else if (input.startsWith("list")) { | ||
| taskManager.listTask(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
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.
Magic number used. A constant may help with readability in the future.