Skip to content
Open
Changes from 4 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
62 changes: 56 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
import java.util.Scanner;

public class Duke {
private static Task[] tasks = new Task[100];

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("Hello! I'm KevBot");
System.out.println("What can I do for you?");


Scanner in = new Scanner(System.in);
String line;
while (in.hasNextLine()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe can check "bye" condition here

line = in.nextLine();
if (line.equals("bye")) {
break;
} else if (line.equals("list")) {
printTasks();
} else if (line.contains("mark")) {
int divider = line.indexOf(" ");
int idx = Integer.parseInt(line.substring(divider + 1)) - 1;
if (idx < 0 || tasks[idx] == null) {
System.out.println("Sorry! That's not a valid task");
Comment thread
kvn-zhang marked this conversation as resolved.
Outdated
continue;
}

markTask(idx, line.startsWith("mark"));
Comment thread
kvn-zhang marked this conversation as resolved.
Outdated
} else {
addTask(line);
}
}
System.out.println("Bye. Hope to see you again soon!");
}

public static void markTask(int index, boolean isDone) {
tasks[index].setStatus(isDone);
if (isDone) {
System.out.println("Nice! I've marked this task as done:");
} else {
System.out.println("OK, I've marked this task as not done yet:");
}
System.out.println(tasks[index].getFormattedTask());
}

public static void printTasks() {
for (int i = 0; i < tasks.length && tasks[i] != null; i++) {
System.out.println((i + 1) + ". " + tasks[i].getFormattedTask());
}
}

public static void addTask(String task) {
for (int i = 0; i < tasks.length; i ++) {
if (tasks[i] == null) {
tasks[i] = new Task(task);
break;
}
}
System.out.println("added: " + task);
}
}