Skip to content
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

[kevinz420] iP #62

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
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

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");
kevinz420 marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

markTask(idx, line.startsWith("mark"));
kevinz420 marked this conversation as resolved.
Show resolved Hide resolved
} 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);
}
}