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

[Nguyen Quang Anh] iP #202

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6118ea3
Level-0
quanganh2810 Jan 25, 2023
9877b90
Add ability to echo input
quanganh2810 Jan 25, 2023
bc1e77d
Add the ability to read and store user commands
quanganh2810 Jan 26, 2023
012958e
Added Task and TaskManager as the class, add Duke's abiity to record,…
quanganh2810 Jan 27, 2023
ba5a640
fix some variable-naming issues and fix further formatting issues in …
quanganh2810 Jan 30, 2023
09c76af
Add Deadline and Event as subclasses
quanganh2810 Feb 4, 2023
dc4925f
fix commit
quanganh2810 Feb 4, 2023
97f41d1
Tidy up the Duke class a little bit by refactoring and shorter print …
quanganh2810 Feb 4, 2023
af773e9
Fix error of not tracking Deadline and Event java files/ added toStri…
quanganh2810 Feb 6, 2023
452032b
Added exceptions to catch error inputs
quanganh2810 Feb 6, 2023
d47c75d
Change the way Duke says goodbye
quanganh2810 Feb 6, 2023
724ee0b
Merge branch 'master' into branch-Level-5
quanganh2810 Feb 6, 2023
4e75a59
change the way Duke says goodbye
quanganh2810 Feb 6, 2023
3cf1411
Create package called "Duke" to store all of the classes
quanganh2810 Feb 6, 2023
c209898
Changing names to comply with the coding standards
quanganh2810 Feb 27, 2023
894b7aa
Add the ability to remove tasks and implement using ArrayList
quanganh2810 Feb 27, 2023
dc3db0f
Add ability to write and read to harddrive
quanganh2810 Feb 27, 2023
b6a0710
Merge branch 'branch-Level-7'
quanganh2810 Feb 27, 2023
5fe873f
Add the ability to read and save data in a file called load.txt properly
quanganh2810 Feb 28, 2023
99531f8
Create extra classes such that the project is more OOP - Parser, UI a…
quanganh2810 Feb 28, 2023
21db370
Add the ability to find task
quanganh2810 Feb 28, 2023
08da801
Add documentation
quanganh2810 Mar 2, 2023
1aaf326
no message
quanganh2810 Mar 2, 2023
c00debc
Merge branch 'branch-A-JavaDoc'
quanganh2810 Mar 2, 2023
c9abb22
Updated the readme file
quanganh2810 Mar 2, 2023
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
30 changes: 16 additions & 14 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Copy link

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

listofItems.listTask();
} else if (WordsinUserCmd[0].equals("mark")) {
} else if (userCmdasWords[0].equals("mark")) {

Choose a reason for hiding this comment

The 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 !");
}
}
20 changes: 10 additions & 10 deletions src/main/java/TaskManager.java
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];
Copy link

Choose a reason for hiding this comment

The 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;

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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;
Copy link

Choose a reason for hiding this comment

The 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
int j = 1;
int counter = 1;

for (Task i : Tasks) {
for (Task i : tasks) {
if (i.getIsDone() == true) {
System.out.print(j);
System.out.print(" [X] ");
Expand All @@ -32,7 +32,7 @@ public void listTask() {
System.out.println(i.getName());
}
j++;
if (j > TasksCount) {
if (j > tasksCount) {
break;
}
}
Expand Down