Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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.

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

public class Poirot {
private static Task[] list_actions = 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.

Use camelCase for variables, E.g. listActions, but a better name will be tasks

private static int last_index = 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.

Perhaps it would be better to use lastIndex instead of last_index.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

size may be a better name than last_index

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 naming the variables with more than one word in camelCase


public static void echo(String msg) {
System.out.println("____________________________________________________________\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.

I noticed that this was repeated many times. Perhaps it would be good to use a utility function to print the horizontal lines instead.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Abstracting the printing of divider to a function will improve readability

System.out.println(msg);
System.out.println("____________________________________________________________\n");
}

public static void print(Task[] list) {
if (last_index == 0) {
System.out.println("____________________________________________________________\n");
System.out.println("No actions available");
} else {
System.out.println("____________________________________________________________\n");
for (int i = 0; i < last_index; i++) {
System.out.println((i + 1) + ".[" + list_actions[i].getStatusIcon() + "]" + list_actions[i].getDescription());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Abstract this to a function and give variable names for list_actions[i].getStatusIcon() and list_actions[i].getDescription to improve code readability

}
}
System.out.println("____________________________________________________________\n");
}

public static void add(Task action) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"add" is a bit ambiguous. It might be better to use "addTask" instead.

list_actions[last_index] = action;
last_index++;
System.out.println("____________________________________________________________\n");
System.out.println("added: " + action.getDescription());
System.out.println("____________________________________________________________\n");
}

public static void main(String[] args) {
System.out.println("____________________________________________________________\n");
System.out.println("Hello! I'm POIROT\n");
System.out.println("What can I do for you?");
System.out.println("____________________________________________________________\n");
boolean working = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this is a boolean, it might be better to call it "isWorking".

Scanner scan = new Scanner(System.in);
while (working) {

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 doing a saving changes to file at the end of each iteration, as such avoiding to call it every time something is changed, reduce duplicate lines

String input = scan.nextLine();
String[] list_input = input.split(" ");
switch (list_input[0]) {
case "list":
print(list_actions);
break;
case "bye":
working = false;
break;
case "mark":
int x = Integer.parseInt(list_input[1]) - 1;
list_actions[x].setDone(true);
System.out.println("____________________________________________________________\n");
System.out.println("Nice! I've marked this task as done:\n");
System.out.print("[" + list_actions[x].getStatusIcon() + "] ");
System.out.println(list_actions[x].getDescription());
System.out.println("____________________________________________________________\n");
break;
case "unmark":
int y = Integer.parseInt(list_input[1]) - 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.

Set a variable for list_input[1] as it is unclear what is that

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use a better name instead of y

list_actions[y].setDone(false);
System.out.println("____________________________________________________________\n");
System.out.println("OK, I've marked this task as not done yet:\n");
System.out.print("[" + list_actions[y].getStatusIcon() + "] ");
System.out.println(list_actions[y].getDescription());
System.out.println("____________________________________________________________\n");
break;
default:
String clearInput = input.trim();
if(clearInput.isEmpty()){
System.out.println("____________________________________________________________\n");
System.out.println("Invalid task");
System.out.println("____________________________________________________________\n");
}
else {
Task newTask = new Task(clearInput);
add(newTask);
}
break;
}
}
System.out.println("____________________________________________________________\n");
System.out.println("Bye. Hope to see you again soon!");
System.out.println("____________________________________________________________\n");
}
}
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;

public Task(String description) {
this.description = description;
this.isDone = false;
}
public String getDescription() {
return description;
}
public String getStatusIcon() {
return (isDone ? "X" : " ");
}
public void setDone(boolean isDone) {
this.isDone = isDone;
}
public void markAsDone(){
this.isDone = true;
}
}