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

[Hao Yun]iP #53

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
65f72a8
Add support for Gradle workflow
j-lum Aug 6, 2019
0112efe
Add sample checkstyle configuration
j-lum Aug 12, 2019
cfd6da7
Change file mode on `gradle` to be executable
j-lum Aug 18, 2019
6e6ace1
Merge pull request #12 from j-lum/gradle+x
j-lum Aug 18, 2019
a3ca5a4
Add configuration for console applications
j-lum Aug 20, 2019
7b60e81
Merge pull request #13 from j-lum/javaexec
j-lum Aug 21, 2019
c4678f7
JavaFX tutorial: Support cross-platform JARs
j-lum Sep 20, 2019
30efbae
JavaFX tutorial: Support cross-platform JARs [#16]
damithc Oct 7, 2019
e253dff
commit Duke.java
Jan 26, 2020
486b841
Add Greet, Echo, Exit to Duke.java
Feb 2, 2020
a7d63e5
Add, List ability
Feb 2, 2020
e282ba7
Add ability to mark DONE
Feb 2, 2020
9c6c52e
Add Todo, Dealine, Event
Feb 9, 2020
f042271
Handle errors with Exceptions
Feb 15, 2020
267000d
Merge branch 'branch-Level-5'
Feb 15, 2020
f91a9c3
add packages duke and duke.task
Feb 15, 2020
6f0b7eb
add Delete command
Feb 16, 2020
40ffee0
add Save
Feb 16, 2020
73097f2
Merge branch 'branch-Level-6'
Feb 16, 2020
1cc9d70
Solve merge conflicts
Feb 16, 2020
a362fd3
use debugger to revise code to realize Save
Feb 16, 2020
f684ba1
revise codes and create a JAR file
Feb 16, 2020
0716c7e
unimportant commit
Feb 24, 2020
abbb7d3
Merge branch 'gradle'
Feb 24, 2020
4d1a286
Use more OOP
Feb 25, 2020
37353f0
Add Find
Feb 25, 2020
a827ebe
Add JavaDoc
Feb 25, 2020
6ff5025
Merge pull request #2 from HAOYUN49/branch-Level-9
HAOYUN49 Feb 25, 2020
15f1dd6
Merge branch 'master' of https://github.com/HAOYUN49/duke
Feb 25, 2020
7bc7f7b
Merge branch 'master' into branch-A-JavaDoc
Feb 25, 2020
90ad6eb
Merge pull request #4 from HAOYUN49/branch-A-JavaDoc
HAOYUN49 Feb 25, 2020
7455fe1
Merge branch 'master' of https://github.com/HAOYUN49/duke
Feb 25, 2020
0e60f25
revise JavaDoc
Feb 26, 2020
12f441a
Add a User Guide
HAOYUN49 Feb 26, 2020
db22159
Update README.md
HAOYUN49 Feb 26, 2020
971f8d8
bug-fixing
Feb 29, 2020
e6ea98c
Merge branch 'master' of https://github.com/HAOYUN49/duke
Feb 29, 2020
c8dca17
revise
Feb 29, 2020
e5fb6da
important revison
Feb 29, 2020
5df9c94
Update README.md
HAOYUN49 Feb 29, 2020
c5c1b7a
delete some unnecessary files
Feb 29, 2020
0e1cf64
Update README.md
HAOYUN49 Mar 1, 2020
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
43 changes: 42 additions & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
import java.util.Scanner;

public class Duke {

private TaskManager manager = new TaskManager();
HAOYUN49 marked this conversation as resolved.
Show resolved Hide resolved

public void exit() {

Choose a reason for hiding this comment

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

You may want to consider changing the name of this method to make it more descriptive, as it could be confused for System.exit()

System.out.println("------------------------------------");
System.out.println("Bye. Hope to see you again soon!");
System.out.println("------------------------------------");
System.out.println();
}

public void run() {

Choose a reason for hiding this comment

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

Similarly, you could consider renaming this method to be more descriptive, as it could be confused for the Java Thread run() method

Scanner in = new Scanner(System.in);
String command;
while(in.hasNextLine()) {
command = in.nextLine();
if(command.equals("bye")) {
return;
} else if (command.equals("list")){
manager.listTask();
} else if (command.startsWith("done")){
manager.markTask(Integer.parseInt(command.substring(5)));

Choose a reason for hiding this comment

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

You may want to consider creating a constant for the number 5 here. Creating a constant can help to give more meaning to the number written here.

Reference Link: Magic Number

Alternatively, you may want to consider changing this line to be more descriptive to avoid confusion, such as
int taskNum = Integer.parseInt(command.substring(5)), or adding a comment to make it clearer what this does, like //command syntax: done 6

} else {
manager.addTask(command);
}
}
}

public void greet(){
System.out.println("------------------------------------");
System.out.println("Hello! I'm Duke");
System.out.println("What can I do for you?");
System.out.println("------------------------------------");
System.out.println();
}

public static void main(String[] args) {
String logo = " ____ _ \n"

Choose a reason for hiding this comment

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

Perhaps you may want to consider putting the logo and the print statements into another method to better implement the SLAP principle such as the greet() method.

+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("Welcome to\n" + logo);
Duke duke = new Duke();
duke.greet();
duke.run();
duke.exit();
}
}
4 changes: 4 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class Task {
String name;
boolean isDone;
}
35 changes: 35 additions & 0 deletions src/main/java/TaskManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class TaskManager {
public static final int MAXIMUM_TASK = 100;
private Task[] tasks = new Task[MAXIMUM_TASK];
private int numOfTasks = 0;

public void addTask(String command) {
System.out.println("------------------------------------");
System.out.println("added: "+ command);
System.out.println("You added a new task, remember to finish it on time!");
System.out.println("------------------------------------");
System.out.println();
Task task = new Task();
task.name = command;
task.isDone = false;
tasks[numOfTasks++] = task;
}

public void listTask() {
System.out.println("------------------------------------");
System.out.println("Here is the list of all tasks you have:");
for(int i = 0; i < numOfTasks; i++) {
System.out.println(String.format("%d.[%c] %s", i+1,(tasks[i].isDone? '✓':'✗'), tasks[i].name));

Choose a reason for hiding this comment

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

You may want to consider seperating this statement into a few more lines to make the code more readable. For example, you may want to first create variables for each item in the print function:
String isDone = tasks[i].isDone? '✓':'✗';

}
System.out.println("------------------------------------");
System.out.println();
}

public void markTask(int taskNo) {
System.out.println("------------------------------------");
System.out.println("Good job! You have done this task:");
System.out.println(" [✓] " + tasks[taskNo-1].name);

Choose a reason for hiding this comment

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

You may want to consider changing this whitespace to \t, to standardise any future tabbed spaces and to reduce confusion for future implementation by other viewers

System.out.println("------------------------------------");
tasks[taskNo-1].isDone = true;
}
}