Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

@telferang telferang Sep 4, 2024

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 boolean variable name "isDone" is well-named, as it clearly indicates its purpose and state.


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

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}
Comment on lines +25 to +27

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 you can make the code more explicit here instead of using ternary if operator?


public void markAsDone() {
this.isDone = true;
}

public void markAsNotDone() {
this.isDone = false;
}
}
111 changes: 111 additions & 0 deletions src/main/java/TulipTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;

public class TulipTask {

@telferang telferang Sep 4, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider renaming the class to "Tulip" as "TulipTask" suggests it might inherit from a "Task" class, which can be misleading.

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 class naming as it is not too long and not short. Nice work!

public static void main(String[] args) {
String logo = " \n" +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent job on storing these strings and not using them as Magic strings!

"--.-- | o --.-- | \n" +
" | . .| .,---. | ,---.,---.|__/ \n" +
" | | || || | | ,---|`---.| \\ \n" +
" ` `---'`---'`|---' ` `---^`---'` `\n" +
" |";

ArrayList<Task> list = new ArrayList<>();

System.out.println(logo);

System.out.println("--------------------------------------------");
System.out.println("Hello, I'm TulipTask");
System.out.println("What can I do for you today?");
System.out.println("--------------------------------------------");

@telferang telferang Sep 4, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider extracting the line as a public static final constant to improve maintainability and avoid duplication.


while (true) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();

// if (Objects.equals(input.toLowerCase(), "bye")) {

@telferang telferang Sep 4, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider removing the commented-out code if it is no longer needed for clarity and to keep the codebase clean.

// break;
// }
//
// if (Objects.equals(input.toLowerCase(), "list")) {
// listTasks(list);
// }
//
// if (input.toLowerCase().contains("mark")) {
// String[] splitStr = input.split(" ");
// System.out.println(splitStr[0]);
// System.out.println(splitStr[1]);
// }

String command;

if (input.toLowerCase().contains("mark")) {
String[] splitStr = input.split(" ");
command = splitStr[0];
} else {
command = input.toLowerCase();
}

switch(command) {
case "list":

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 you could refactor to avoid magic strings!

listTasks(list);
break;

case "mark":
String[] splitStr = input.split(" ");
int index = Integer.parseInt(splitStr[1]) - 1;
markAsDone(list.get(index));
break;

case "unmark":
String[] split = input.split(" ");
int idx = Integer.parseInt(split[1]) - 1;

@telferang telferang Sep 4, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using more descriptive variable names, such as "index" instead of "idx", for better readability.

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 avoid different levels of abstraction here (i.e.listTasks(list) and String[] splitStr = input.split(" ") and int index = Integer.parseInt(splitStr[1]) - 1

markAsNotDone(list.get(idx));
break;

case "bye":
System.out.println("--------------------------------------------");
System.out.println("Bye! Hope to see you again soon :)");
System.out.println("--------------------------------------------");
return;

default:
Task task = new Task(command);
list.add(task);
echo(task);
break;
}
}
}

public static void echo (Task task) {
System.out.println("--------------------------------------------");
System.out.println("added: " + task.description);
System.out.println("--------------------------------------------");
}

public static void listTasks (ArrayList<Task> list) {
System.out.println("--------------------------------------------");
System.out.println("Here are your tasks: ");
for (int i = 0; i < list.size(); i++) {
Task task = list.get(i);
System.out.println((i + 1) + ". " + "[" + task.getStatusIcon() + "] " + task.description);
}
System.out.println("--------------------------------------------");
}

public static void markAsDone(Task task) {
task.markAsDone();
System.out.println("--------------------------------------------");
System.out.println("Great job! I have marked this task as done: \n" + " [" + task.getStatusIcon() + "] " + task.description);
System.out.println("--------------------------------------------");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you need to fix the spacings here.

public static void markAsNotDone(Task task) {
task.markAsNotDone();
System.out.println("--------------------------------------------");
System.out.println("Okay, I have marked this task as not done: \n" + " [" + task.getStatusIcon() + "] " + task.description);
System.out.println("--------------------------------------------");
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You may consider adding comment statements here to explain to other engineers what and why you are doing this.