-
Notifications
You must be signed in to change notification settings - Fork 187
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
[Liu Ze Hui] iP #192
base: master
Are you sure you want to change the base?
[Liu Ze Hui] iP #192
Changes from 4 commits
215dbb8
da5bbbb
5b9ead6
bec25f4
6c1ed56
5769d82
52ab112
09dad06
8934c19
5667b2a
4c010a4
1163469
ca4c4c6
755cb31
75014ee
e3469f4
96d7ab0
6e92e2d
058b7df
1f259ca
666aaa8
12b1ddd
09c7795
ed304d3
a5c5aed
0612989
2df056b
db07c45
f540c91
df0007c
6a14058
8c65295
84af7ed
306396e
674d503
017bdec
302e239
5491c80
5fd1291
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,58 @@ | ||
import java.util.Scanner; | ||
//so scanner class can be used | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
public static void printLine() { | ||
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 try to rename it to something that indicates it is also printing a newline ie)printlnLine |
||
System.out.println("________________________________________"); | ||
} | ||
public static void printShortLine() { | ||
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 try to rename it to something that indicates it is also printing a newline ie)printlnShortLine |
||
System.out.println("_____________"); | ||
} | ||
public static void printHello() { | ||
String logo = | ||
"__ __ ___ _____ \n" | ||
+ "\\ \\ / / / _ \\ | ___ |\n" | ||
+ " \\ Y / | | | | | | \n" | ||
+ " \\ / | | | | | | \n" | ||
+ " | | | |_| | ___| | \n" | ||
+ " |_| \\___/ |____/ \n"; | ||
printLine(); | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println("Hello! I'm YOJ"); | ||
System.out.println("What can I do for you?"); | ||
printLine(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
printHello(); | ||
// get user input | ||
Scanner in = new Scanner(System.in); | ||
String userInput; | ||
userInput = in.nextLine(); | ||
|
||
while(!userInput.equals("bye")) { | ||
printShortLine(); | ||
System.out.println("added: " + userInput); | ||
printLine(); | ||
if (userInput.equals("list")) { | ||
Task.printList(); | ||
} else if(userInput.matches("mark \\d+")) { | ||
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. may want to set constants to identify the regex expression, as regex may not be intuitively readable |
||
String[] taskIndex = userInput.split(" "); | ||
int index = Integer.parseInt(taskIndex[1]); | ||
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. Consider changing these two lines to a method? So that you can use again in "unmark" condition as well. |
||
Task.markDone(index-1); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println(" [X] " + Task.tasks[index-1]); | ||
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. Since you already have the |
||
} else if(userInput.matches("unmark \\d+")) { | ||
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. may want to set constants to identify the regex expression, as regex may not be intuitively readable |
||
String[] taskIndex = userInput.split(" "); | ||
int index = Integer.parseInt(taskIndex[1]); | ||
Task.markUndone(index-1); | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
System.out.println(" [ ] " + Task.tasks[index-1]); | ||
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. Consider extracting these lines to a method called |
||
} else { | ||
Task.addTask(userInput); | ||
} | ||
userInput = in.nextLine(); | ||
} | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public class Task { | ||
protected static String[] tasks = new String[100]; | ||
protected static boolean[] tasksCompleted = new boolean[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. whichTasksCompleted sounds like a better variable name as the variable name tasksCompleted sounds like an integer 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. Please avoid the use of Magic Numbers. Instead declare a constant with the value you deem is right, and use that constant. Or better, you may choose to use 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. For this line, I may suggest you to refactor Sometimes it may happen that, you delete a protected boolean isTaskDone; |
||
protected static int taskNumber; | ||
|
||
public Task() { | ||
taskNumber = 0; | ||
} | ||
|
||
public static void addTask(String userInput) { | ||
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 like the way you named your methods, which are all in camalCase. Good job! |
||
tasks[taskNumber] = userInput; | ||
tasksCompleted[taskNumber] = false; | ||
taskNumber++; | ||
} | ||
public static void markDone(int taskNumber) { | ||
tasksCompleted[taskNumber] = true; | ||
} | ||
|
||
public static void markUndone(int taskNumber) { | ||
tasksCompleted[taskNumber] = false; | ||
} | ||
public static String getStatusIcon(int taskNumber) { | ||
return (tasksCompleted[taskNumber] ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public static void printList() { | ||
for(int i = 0; i < taskNumber; i++) { | ||
System.out.println(i+1 + ". [" + getStatusIcon(i) + "] " + tasks[i]); | ||
} | ||
Duke.printLine(); | ||
} | ||
} |
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.
Consider changing the class name to
Yoj
? Since you named your bot to be this.