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

[Yan Zaiya] iP #211

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
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
47 changes: 47 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
import java.util.Scanner;

public class Duke {
public static String DIVIDER_LINE = "______________________________\n";

public static void main(String[] args) {

Choose a reason for hiding this comment

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

Your main method feels a bit long, can consider modularizing it. According to the textbook, the recommendation is to have 30 LOC.

String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
String greet = DIVIDER_LINE
+ "Hello! I'm Duke\n"
+ "What can i do for you\n"
+ DIVIDER_LINE;
Copy link

Choose a reason for hiding this comment

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

Good job combining the welcome statement into one string

System.out.println(greet);
boolean shouldContinue = true;
Scanner in = new Scanner(System.in);
//String[] tasks = new String[100];
Copy link

Choose a reason for hiding this comment

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

perhaps remove this comment if you are no longer using it

int taskCount = 0;
String action;
Task[] tasks = new Task[100];
while (shouldContinue) {
action = in.nextLine();
if (action.equals("bye")) {
System.out.println(DIVIDER_LINE + "Bye. Hope to see you again soon!\n" + DIVIDER_LINE);
shouldContinue = false;
}else if (action.equals("list")) {
System.out.print(DIVIDER_LINE);
for (int i = 0; i < taskCount; i += 1) {
System.out.println(Integer.toString(i + 1) + "." + "" +tasks[i].getStatusIcon()
+ " " +tasks[i].description);
}
System.out.println(DIVIDER_LINE);
}else if (action.startsWith("mark")){
int dividerPos = action.indexOf(" ");
Copy link

Choose a reason for hiding this comment

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

Perhaps you could spell out "position" or change it to "Index"

int toBeMarked = Integer.parseInt(action.substring(dividerPos + 1)) - 1;
tasks[toBeMarked].markAsDone();
System.out.println(DIVIDER_LINE + "Nice! I've marked this task as done:\n"
+ tasks[toBeMarked].getStatusIcon() + " " + tasks[toBeMarked].description
+ "\n" + DIVIDER_LINE);
Copy link

Choose a reason for hiding this comment

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

I think this print statement is a bit lengthy. Perhaps you could use the ToString override method in your classes to shorten it

Copy link

Choose a reason for hiding this comment

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

Good job in ensuring that the character count of each line should not exceed 120 characters.

}else if (action.startsWith("unmark")) {
int dividerPos = action.indexOf(" ");
Copy link

Choose a reason for hiding this comment

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

Perhaps you could consider writing your variable name in full?

int toBeUnmarked = Integer.parseInt(action.substring(dividerPos + 1)) - 1;
tasks[toBeUnmarked].markAsUndone();
System.out.println(DIVIDER_LINE + "Nice! I've marked this task as undone:\n"
+ tasks[toBeUnmarked].getStatusIcon() + " " + tasks[toBeUnmarked].description
+ "\n" + DIVIDER_LINE);
}else {
Copy link

Choose a reason for hiding this comment

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

Should there be a spacing between the curly brackets and the "else if" and the "else"?

tasks[taskCount] = new Task(action);
taskCount += 1;
System.out.println(DIVIDER_LINE + "added: " + action + "\n" + DIVIDER_LINE);
}
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 markAsDone() {
this.isDone = true;
}

public void markAsUndone() {
this.isDone = false;
}

//...
Copy link

Choose a reason for hiding this comment

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

Perhaps you could remove this comment

}