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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

20 changes: 20 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public void print() {
System.out.print("[" + (isDone ? "X" : " ") + "] ");
System.out.println(description);
}

//...
}
68 changes: 68 additions & 0 deletions src/main/java/Wen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import java.util.Scanner;

public class Wen {

private static int taskCount = 0;
private static Task[] 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.

avoid using magic numbers, declare 100 as a constant like TASKS_SIZE


public static void main(String[] args) {
initializeAndGreet();

String input = "";
Scanner in = new Scanner(System.in);

while (!input.equals("bye")) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The nested loop is not correctly indented, and consider whether you need the outer loop or not.

input = in.nextLine();
final String command = input.split(" ", 2)[0];
final String commandArgs = input.split(" ", 2).length > 1 ? input.split(" ", 2)[1] : "";

switch (command) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be no indentation for case clauses, refer to the Java Coding standard.

case "bye":
break;

case "list":
printTasks();
break;



default:
addTask(input);
// System.out.println("Unknown command \""+command+"\"! Double check your message and try running again~");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Delete the codes that are commented and not used.

break;
}
}

terminateAndGoodbye();
}


private static void initializeAndGreet() {
System.out.println("Hello, I'm Wen!");
System.out.println("Let me know what I can help you with~☆");
}

private static void terminateAndGoodbye() {
System.out.println();
System.out.println("Aw, you're already going?");
System.out.println("It's okay, let's meet again soon!");

System.exit(0);
}

private static void printTasks() {
System.out.println("You currently have " + taskCount + " tasks!");
for (int i=0; i<taskCount; i++) {
tasks[i].print();
}
}

private static void addTask(String description) {
tasks[taskCount] = new Task(description);

System.out.println("Task added succesfully:");
tasks[taskCount].print();

taskCount++;
}
}