Skip to content

[Ming Gao Rickie Li] iP#469

Open
MGRL2201 wants to merge 38 commits into
nus-cs2103-AY2122S1:masterfrom
MGRL2201:master
Open

[Ming Gao Rickie Li] iP#469
MGRL2201 wants to merge 38 commits into
nus-cs2103-AY2122S1:masterfrom
MGRL2201:master

Conversation

@MGRL2201

@MGRL2201 MGRL2201 commented Aug 26, 2021

Copy link
Copy Markdown

Duke

“Your mind is for having ideas, not holding them.” – David Allen (source)

Duke frees your mind of having to remember things you need to do. It's,

  • EXTREMELY FAST to use
  • easy to learn
  • text-based

All you need to do is,

  1. download it from here
  2. double-click it.
  3. add your tasks with todo, event or deadline commands
  4. let it manage your tasks for you 😉

Best of all, Duke is FREE

Features:

  • Managing Tasks
  • Managing Deadlines (coming soon)
  • Reminders (coming soon)

If you're a Java programmer, you can use it to practice Java too. Here's the main method:

public static void main(String[] args) {
    new Duke("Data\\taskList.txt").run();
}

@MGRL2201 MGRL2201 changed the title [Ming Gao Rickie Li] [Ming Gao Rickie Li] ip Aug 26, 2021
@MGRL2201 MGRL2201 changed the title [Ming Gao Rickie Li] ip [Ming Gao Rickie Li] iP Aug 26, 2021

@Justinhoejj Justinhoejj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey, code looks acceptable to me. Gave some comments on how you could further abstract some methods, hope that will help in improving the code quality. Do note the naming of test methods as well. Otherwise good job on the project! 👍

Comment thread src/main/java/duke/Deadline.java Outdated
public class Deadline extends Task {

protected String by;
protected LocalDate date;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If these variables are not used in other parts of the code base consider changing the accessor to private.

Comment thread src/main/java/duke/Deadline.java Outdated
Comment on lines +6 to +7
protected String by;
protected LocalDate date;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider declaring variables as final if the attributes are not expected to change.

Comment thread src/main/java/duke/Duke.java Outdated
Comment on lines +7 to +9
private Storage storage;
private Ui ui;
private String filePath;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider declaring as final.

Comment thread src/main/java/duke/Event.java Outdated
Comment on lines +6 to +7
protected String at;
protected LocalDate date;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider changing to private final.

Comment thread src/main/java/duke/Parser.java Outdated
Comment on lines +12 to +30
if (input.replaceAll("\\s","").toLowerCase().equals("bye")) {
return "bye";
} else if (inputLower.replaceAll("\\s", "").equals("list")) {
return "list";
} else if (inputLower.length() > 3 && inputLower.substring(0, 4).equals("done")) {
return "done";
} else if (inputLower.length() > 5 && inputLower.substring(0, 6).equals("delete")) {
return "delete";
} else if (inputLower.length() >= 4 && inputLower.substring(0, 4).equals("todo")) {
return "todo";
} else if (inputLower.length() >= 5 && inputLower.substring(0, 5).equals("event")) {
return "event";
} else if (inputLower.length() >= 8 && inputLower.substring(0, 8).equals("deadline")) {
return "deadline";
} else if (inputLower.length() >=4 && inputLower.substring(0, 4).equals("find")) {
return "find";
} else {
return "InvalidCommand";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using case switch. Additionally, consider implementing a general remove first word method that extracts the string before the first space.

Comment thread src/main/java/duke/Storage.java Outdated
fileReader.close();
}
} catch (IOException e) {
System.out.println("An error occurred.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider specifying the type of error. eg. error loading tasks.

Comment thread src/main/java/duke/Ui.java Outdated
Comment on lines +30 to +31
System.out.println(separator);
System.out.println(" You have no tasks in your list!");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A UI component that can be abstracted to a generic method to format responses. Since these lines of code are used extensively in the run method, abstracting the method will reduce code re-write .

Comment thread src/main/java/duke/Ui.java Outdated
Comment on lines +79 to +82
System.out.println(" ____________________________________________________________");
System.out.println(" Got it. I've added this task:");
System.out.println(" " + t.toString());
System.out.println(String.format(" Now you have %d tasks in the list.", list.size()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These lines of codes are used more than twice. Consider abstracting to a method to enhance ease of readability and maintainability.

Comment thread src/main/java/duke/Ui.java Outdated
Comment on lines +112 to +117
Task t = list.get(i);
if (list.get(i).description.toLowerCase().contains(query)) {
tasksContainingQuery.add(t);
}
}
if (tasksContainingQuery.size() == 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Logic here involves the task list. It may be more appropriate to extract into a method in a task list class. Ideally UI takes string from user to pass to pass to parser and takes string from duke and prints, since the UI is an interface between duke and user. All other logic can be defined in other classes.


import static org.junit.jupiter.api.Assertions.assertEquals;

public class DukeTest {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider following the test method naming convention featureUnderTest_testScenario_expectedBehavior().

@HolmesJJ HolmesJJ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like your clear code and it is esay to understand. 👍 Perhaps more comments for the class and method will be much easier to understand. 😄

Comment thread src/main/java/duke/Deadline.java Outdated
package duke;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Deadline extends Task {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps need a descriptive header comments for the Parser class? 🤔

Comment thread src/main/java/duke/Deadline.java Outdated
protected String by;
protected LocalDate date;

public Deadline(String description, String by) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps need a descriptive header comments for the Deadline method? 🤔
And I noticed the same issue in several other places below.


import java.util.Scanner;

public class Duke {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps need a descriptive header comments for the Duke class? 🤔

private Ui ui;
private String filePath;

public Duke(String filePath) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps need a descriptive header comments for the Duke method? 🤔
And I noticed the same issue in several other places below.

Comment thread src/main/java/duke/Duke.java Outdated
}

public static void main(String[] args) {
new Duke("C:\\Users\\Rickie\\Documents\\University\\Year 2\\Semester 1\\CS2103T\\ip\\Data\\taskList.txt").run();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be wrapped to next line? 🤔

Comment thread src/test/java/DukeTest.java Outdated
@Test
public void uiWelcomeTest() {
String separator = " ____________________________________________________________";
String message = separator + "\n" + " Hello! I'm Duke" + "\n" + " What can I do for you?" + "\n" + separator;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps need an empty line between description and parameter section? 🤔

Comment thread src/test/java/DukeTest.java Outdated
Duke duke = new Duke("C:\\Users\\Rickie\\Documents\\University\\Year 2\\Semester 1\\CS2103T\\ip\\Data\\taskList.txt");

@Test
public void parserTest1() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps need a descriptive header comments for the parserTest1 method? 🤔
And I noticed the same issue in several other places below.

Comment thread src/main/java/duke/Ui.java Outdated
}

/**
* Returns updated user task list and prints feedback to the user based on their input

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps need a full stop at the end? 🤔

Comment thread src/main/java/duke/Todo.java Outdated
package duke;
public class Todo extends Task {

public Todo(String description) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps need a descriptive header comments for the Todo method? 🤔
And I noticed the same issue in several other places below.

Comment thread src/main/java/duke/Task.java Outdated
protected String description;
protected boolean isDone;

public Task(String description) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps need a descriptive header comments for the Task method? 🤔
And I noticed the same issue in several other places below.

@Chesterwongz Chesterwongz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

Comment thread src/test/java/DukeTest.java Outdated

public class DukeTest {

Duke duke = new Duke("C:\\Users\\Rickie\\Documents\\University\\Year 2\\Semester 1\\CS2103T\\week 2\\ip\\Data\\taskList.txt");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using relative path instead of absolute path, incase project structure changes in the future

Comment thread src/main/java/duke/Todo.java Outdated
@@ -0,0 +1,12 @@
package duke;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor style issue here, but there should always be a new line after package statement

Comment thread src/main/java/duke/Ui.java Outdated
System.out.println(String.format(" %d. %s", (i + 1), item.toString()));
}
}
} else if (parsedInput.equals("done")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

perhaps the throwing of exceptions should be done in the Parser rather than Ui handler, since the parser handles valid and invalid input

There is no code in place to indicate possible bugs.

Assertion statements have been added to Duke class to ensure user input
and program output are not null.

The impact of assertions on performance is low and provides a safety
net to ensure the user input and program output are as expected.
MGRL2201 and others added 5 commits September 9, 2021 14:43
The code needs to be more readable and abstract.

Further abstracting code has made the code easier to read and follow
along.

Abstracting shortens method length and good naming of abstracted methods
allow for more readable code.

@ramapriyan912001 ramapriyan912001 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job overall!
Just some tweaks needed!

import java.time.format.DateTimeFormatter;
public class Event extends Task {

protected String at;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"at" is perhaps not descriptive enough

Comment on lines +60 to +64
if (this.date != null) {
return "[E]" + super.toString() + " (at: "
+ this.date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")";
} else {
return "[E]" + super.toString() + " (at: " + this.at + ")";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Some use of magic literals here.

Comment thread src/main/java/duke/Parser.java Outdated
Comment on lines +10 to +33
public static String parse(String input) {
String inputLower = input.toLowerCase();
if (input.replaceAll("\\s", "").toLowerCase().equals("bye")) {
return "bye";
} else if (inputLower.replaceAll("\\s", "").equals("list")) {
return "list";
} else if (inputLower.length() > 3 && inputLower.substring(0, 4).equals("done")) {
return "done";
} else if (inputLower.length() > 5 && inputLower.substring(0, 6).equals("delete")) {
return "delete";
} else if (inputLower.length() >= 4 && inputLower.substring(0, 4).equals("todo")) {
return "todo";
} else if (inputLower.length() >= 5 && inputLower.substring(0, 5).equals("event")) {
return "event";
} else if (inputLower.length() >= 8 && inputLower.substring(0, 8).equals("deadline")) {
return "deadline";
} else if (inputLower.length() >= 4 && inputLower.substring(0, 4).equals("find")) {
return "find";
} else if (inputLower.length() >= 6 && inputLower.substring(0, 6).equals("update")) {
return "update";
} else {
return "InvalidCommand";
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done, very neat, and handles commands of different cases!

Comment thread src/main/java/duke/Storage.java Outdated
} else {
Event e = new Event(splitString[2], splitString[3]);
if (splitString[1].equals("1")) {
e.markAsDone();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could perhaps be SLAP-ed harder?

Comment thread src/main/java/duke/Ui.java Outdated
* @param input user input
* @return updated task list
*/
public String run(Storage storage, String input) throws DukeException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This method could be SLAP-ed harder perhaps?

Comment thread src/main/java/duke/Ui.java Outdated
}
}

private String getDeleteTaskString(ArrayList<Task> list, String input, Storage storage) throws DukeException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well modularised! Great job!

Comment thread text-ui-test/EXPECTED.TXT
2. [T][ ] read book
3. [D][X] return book (by: Sunday)
4. [E][ ] project meeting (at: Monday 2-4pm)
____________________________________________________________

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The line separation definitely helps. Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants