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

[Liu Ze Hui] iP #192

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
215dbb8
add Duke.java level 0
liuzehui03 Feb 2, 2024
da5bbbb
added level-1
liuzehui03 Feb 8, 2024
5b9ead6
Level-2
liuzehui03 Feb 8, 2024
bec25f4
Level-3
liuzehui03 Feb 8, 2024
6c1ed56
no message
liuzehui03 Feb 22, 2024
5769d82
Level-5
liuzehui03 Feb 22, 2024
52ab112
changes to Deadline event and Todo
liuzehui03 Mar 5, 2024
09dad06
testing
liuzehui03 Mar 5, 2024
8934c19
handle exceptions
liuzehui03 Mar 6, 2024
5667b2a
package
liuzehui03 Mar 6, 2024
4c010a4
Merge branch 'branch-Level-5'
liuzehui03 Mar 6, 2024
1163469
rename package
liuzehui03 Mar 6, 2024
ca4c4c6
rename package
liuzehui03 Mar 6, 2024
755cb31
Merge branch 'trial'
liuzehui03 Mar 6, 2024
75014ee
created List.java
liuzehui03 Mar 6, 2024
e3469f4
changed to ArrayList
liuzehui03 Mar 6, 2024
96d7ab0
delete function fixed
liuzehui03 Mar 6, 2024
6e92e2d
fixing save data
liuzehui03 Mar 7, 2024
058b7df
Merge branch 'branch-Level-6'
liuzehui03 Mar 7, 2024
1f259ca
Merge branch 'branch-Level-7'
liuzehui03 Mar 7, 2024
666aaa8
fix save function
liuzehui03 Mar 7, 2024
12b1ddd
JAR file
liuzehui03 Mar 7, 2024
09c7795
added Storage class
liuzehui03 Mar 7, 2024
ed304d3
added Ui class
liuzehui03 Mar 7, 2024
a5c5aed
added taskList and parser
liuzehui03 Mar 8, 2024
0612989
added find task feature
liuzehui03 Mar 8, 2024
2df056b
Revert "added find task feature"
liuzehui03 Mar 8, 2024
db07c45
find task feature
liuzehui03 Mar 8, 2024
f540c91
Merge pull request #1 from liuzehui03/branch-Level-9
liuzehui03 Mar 8, 2024
df0007c
fix some bugs
liuzehui03 Mar 8, 2024
6a14058
added comments
liuzehui03 Mar 8, 2024
8c65295
more comments
liuzehui03 Mar 8, 2024
84af7ed
Merge branch 'branch-A-JavaDoc'
liuzehui03 Mar 8, 2024
306396e
finallsing documentation READme
liuzehui03 Mar 8, 2024
674d503
updated link
liuzehui03 Mar 8, 2024
017bdec
no message
liuzehui03 Mar 8, 2024
302e239
no message
liuzehui03 Mar 8, 2024
5491c80
comment
liuzehui03 Mar 8, 2024
5fd1291
Merge remote-tracking branch 'origin/master'
liuzehui03 Mar 8, 2024
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
12 changes: 12 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Deadline extends Task {
protected String by;

public Deadline (String description, String by){
super(description);
this.by = by;
}
Copy link

Choose a reason for hiding this comment

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

Advisable to have a uniform spacing strategy, to enhance code readability.

Suggested change
public Deadline (String description, String by){
super(description);
this.by = by;
}
public Deadline (String description, String by) {
super(description);
this.by = by;
}


public String toString() {
return "[D] " + super.toString() + " (by: " + by + ")";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import static com.sun.beans.introspect.PropertyInfo.Name.description;

public class Event extends Task{
private String at;

public Event (String description, String at){
super();
this.at = at;
}

public String getAt(){
return at;
}

public String toString() {
return "[E] " + super.toString() + description + " (at: " + at + ")";
}
}
Copy link

Choose a reason for hiding this comment

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

It is usually a practise to use this.method() or this.variable when that method or variable belongs to the Class.

This change can be made at other places as well :)

Suggested change
public String getAt(){
return at;
}
public String toString() {
return "[E] " + super.toString() + description + " (at: " + at + ")";
}
}
public String getAt(){
return this.at;
}
public String toString() {
return "[E] " + super.toString() + this.description + " (at: " + this.at + ")";
}
}

32 changes: 32 additions & 0 deletions src/main/java/Task.java
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];

Choose a reason for hiding this comment

The 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

Copy link

Choose a reason for hiding this comment

The 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 ArrayList which dynamically resizes as per need, and you may not require such constants. However, everything comes at a tradeoff, so you may do some research into Array vs ArrayList and choose what fits the best for your needs.

Reference: https://nus-cs2113-ay2324s2.github.io/website/se-book-adapted/chapters/codeQuality.html#avoid-magic-numbers

Copy link

Choose a reason for hiding this comment

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

For this line, I may suggest you to refactor Task Class to have a boolean variable isDone. As a new Task is created, that isDone variable is unique to that task and may be updated as required. This is also efficient as you don't have to maintain an extra Array.

Sometimes it may happen that, you delete a Task and you may forget to update it in this other Array, making your code fragile and more bug prone.

    protected boolean isTaskDone;

protected static int taskNumber;

public Task(String description) {
taskNumber = 0;
}

public static void addTask(String userInput) {

Choose a reason for hiding this comment

The 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]);
}
Yoj.printLine();
}
}
12 changes: 12 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Todo extends Task {
public Todo (String description){
super(description);
}

// Prints task
public void printTask(){
System.out.print("[T][");

System.out.println("] " + description);
}
}
Copy link

Choose a reason for hiding this comment

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

Missing EOF. Add an extra empty line at the end of file (EOF), as this indicates the end of the file.

You may configure IntelliJ to add this automatically for you when hit CTRL/CMD + S.

58 changes: 58 additions & 0 deletions src/main/java/Yoj.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.util.Scanner;
//so scanner class can be used

public class Yoj {
public static void printLine() {
System.out.println("________________________________________");
}
public static void printShortLine() {
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+")) {
Copy link

Choose a reason for hiding this comment

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

You may want to declare all the regex expressions being used as constants. This also allows you to just update the constant and reuse that at multiple places, without needing to update it at every place you declared it initially.

String[] taskIndex = userInput.split(" ");
int index = Integer.parseInt(taskIndex[1]);
Task.markDone(index-1);
System.out.println("Nice! I've marked this task as done:");
System.out.println(" [X] " + Task.tasks[index-1]);
} else if(userInput.matches("unmark \\d+")) {
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]);
} else {
Task.addTask(userInput);
}
userInput = in.nextLine();
}
Copy link

Choose a reason for hiding this comment

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

This code block can be abstracted to improve the code readability. Usually, methods should not be longer than 30 Lines of Code.

Reference: https://nus-cs2113-ay2324s2.github.io/website/se-book-adapted/chapters/codeQuality.html#avoid-long-methods

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