-
Notifications
You must be signed in to change notification settings - Fork 200
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
base: master
Are you sure you want to change the base?
[Yan Zaiya] iP #211
Changes from 3 commits
948e367
ed23c92
3443a1a
e45b3f9
266f1af
348e162
7a661ff
cade921
fa052ea
080beee
483db36
33aed0d
4392566
22f3a3f
226cefa
1d2e544
8e79147
4cb3354
0d982de
8e72009
0d0c7ea
20905f4
2940847
8e45cf8
07ecaaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(" "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(" "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
} | ||
} |
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; | ||
} | ||
|
||
//... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps you could remove this comment |
||
} |
There was a problem hiding this comment.
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.