-
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
[Nguyen Quang Anh] iP #202
base: master
Are you sure you want to change the base?
Changes from 1 commit
6118ea3
9877b90
bc1e77d
012958e
ba5a640
09c76af
dc4925f
97f41d1
af773e9
452032b
d47c75d
724ee0b
4e75a59
3cf1411
c209898
894b7aa
dc3db0f
b6a0710
5fe873f
99531f8
21db370
08da801
1aaf326
c00debc
c9abb22
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 |
---|---|---|
|
@@ -10,30 +10,32 @@ public static void main(String[] args) { | |
System.out.println("Hello from\n" + logo); | ||
System.out.println("Hello! I'm Duke"); | ||
System.out.println("What can I do for you ?"); | ||
Scanner ScanObj = new Scanner(System.in); | ||
|
||
Scanner scanObj = new Scanner(System.in); | ||
TaskManager listofItems = new TaskManager(); | ||
String UserCmd = ScanObj.nextLine(); | ||
String userCmd = scanObj.nextLine(); | ||
int taskId = 0; | ||
while (!UserCmd.equals("bye")) { | ||
String[] WordsinUserCmd = UserCmd.split(" "); | ||
System.out.println(WordsinUserCmd[0]); | ||
if (UserCmd.equals("list")) { | ||
|
||
while (!userCmd.equals("bye")) { | ||
String[] userCmdasWords = userCmd.split(" "); | ||
System.out.println(userCmdasWords[0]); | ||
if (userCmd.equals("list")) { | ||
listofItems.listTask(); | ||
} else if (WordsinUserCmd[0].equals("mark")) { | ||
} else if (userCmdasWords[0].equals("mark")) { | ||
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. userCmdasWords is a bit confusing to reader. |
||
System.out.println("this is a mark command"); | ||
listofItems.markTask(Integer.parseInt(WordsinUserCmd[1]) - 1); | ||
} else if (WordsinUserCmd[0].equals("unmark")) { | ||
listofItems.markTask(Integer.parseInt(userCmdasWords[1]) - 1); | ||
} else if (userCmdasWords[0].equals("unmark")) { | ||
System.out.println("this is a unmark command"); | ||
listofItems.unmarkTask(Integer.parseInt(WordsinUserCmd[1]) - 1); | ||
listofItems.unmarkTask(Integer.parseInt(userCmdasWords[1]) - 1); | ||
} else { | ||
System.out.print("added: "); | ||
System.out.println(UserCmd); | ||
listofItems.addTask(UserCmd, taskId); | ||
System.out.println(userCmd); | ||
listofItems.addTask(userCmd, taskId); | ||
taskId++; | ||
} | ||
UserCmd = ScanObj.nextLine(); | ||
userCmd = scanObj.nextLine(); | ||
} | ||
|
||
scanObj.close(); | ||
System.out.println("Bye. Hope to see you again soon !"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,27 +1,27 @@ | ||||||
public class TaskManager { | ||||||
private Task[] Tasks = new Task[100]; | ||||||
private int TasksCount = 0; | ||||||
private Task[] tasks = new Task[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. Great! Array specifiers is attached to the type not the variable. |
||||||
private int tasksCount = 0; | ||||||
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. Can be taskCount instead of tasksCount to follow naming convention. |
||||||
|
||||||
public void addTask(String name, int id) { | ||||||
Tasks[TasksCount] = new Task(name, false, id); | ||||||
TasksCount++; | ||||||
tasks[tasksCount] = new Task(name, false, id); | ||||||
tasksCount++; | ||||||
} | ||||||
|
||||||
public void markTask(int id) { | ||||||
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. Can consider combining markTask and unmarkTask into one function. |
||||||
Tasks[id].setIsDone(true); | ||||||
tasks[id].setIsDone(true); | ||||||
System.out.println("The task has been marked as done!"); | ||||||
System.out.println("[X] " + Tasks[id].getName()); | ||||||
System.out.println("[X] " + tasks[id].getName()); | ||||||
} | ||||||
|
||||||
public void unmarkTask(int id) { | ||||||
Tasks[id].setIsDone(false); | ||||||
tasks[id].setIsDone(false); | ||||||
System.out.println("The task has been marked as NOT done!"); | ||||||
System.out.println("[ ] " + Tasks[id].getName()); | ||||||
System.out.println("[ ] " + tasks[id].getName()); | ||||||
} | ||||||
|
||||||
public void listTask() { | ||||||
int j = 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 the variable name. Variables named j, k etc. should be used for nested loops only.
Suggested change
|
||||||
for (Task i : Tasks) { | ||||||
for (Task i : tasks) { | ||||||
if (i.getIsDone() == true) { | ||||||
System.out.print(j); | ||||||
System.out.print(" [X] "); | ||||||
|
@@ -32,7 +32,7 @@ public void listTask() { | |||||
System.out.println(i.getName()); | ||||||
} | ||||||
j++; | ||||||
if (j > TasksCount) { | ||||||
if (j > tasksCount) { | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
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.
Perhaps you can consider using switch instead of multiple if-else statements to make your code cleaner and more readable