Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
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 + ")";
}
}
16 changes: 16 additions & 0 deletions src/main/java/Event.java
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 + ")";
}
}
37 changes: 37 additions & 0 deletions src/main/java/Task.java
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();
}
}





32 changes: 32 additions & 0 deletions src/main/java/TaskManager.java
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];
Copy link
Copy Markdown

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.

taskCount = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Donot use magic numbers in the code. You can replace it with a constant so that it will improve readability.

}

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());
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/Todo.java
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();
}
}

46 changes: 46 additions & 0 deletions src/main/java/chatbot.java
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();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to create a class for task management

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get index could be abstracted into a function to make the code more readable here.

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();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the input filtering be abstracted to make this part more readable?

Event event = new Event(description, from, to);
taskManager.addTask(event);
} else if (input.startsWith("list")) {
taskManager.listTask();
}
}
}

}