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

[Ming Gao Rickie Li] iP #469

Open
wants to merge 38 commits into
base: master
Choose a base branch
from

Conversation

MGRL2201
Copy link

@MGRL2201 MGRL2201 commented Aug 26, 2021

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

@Justinhoejj Justinhoejj left a comment

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! 👍

public class Deadline extends Task {

protected String by;
protected LocalDate date;

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 on lines 6 to 7
protected String by;
protected LocalDate date;

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 on lines 7 to 9
private Storage storage;
private Ui ui;
private String filePath;

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 on lines 6 to 7
protected String at;
protected LocalDate date;

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 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";
}

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.

fileReader.close();
}
} catch (IOException e) {
System.out.println("An error occurred.");

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 on lines 30 to 31
System.out.println(separator);
System.out.println(" You have no tasks in your list!");

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 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()));

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

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 {

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().

Copy link

@HolmesJJ HolmesJJ left a comment

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. 😄

package duke;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Deadline extends Task {
Copy link

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? 🤔

protected String by;
protected LocalDate date;

public Deadline(String description, String by) {
Copy link

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

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

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.

}

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

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? 🤔

@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

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? 🤔

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

@Test
public void parserTest1() {
Copy link

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.

}

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

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? 🤔

package duke;
public class Todo extends Task {

public Todo(String description) {
Copy link

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.

protected String description;
protected boolean isDone;

public Task(String description) {
Copy link

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.

Copy link

@Chesterwongz Chesterwongz left a comment

Choose a reason for hiding this comment

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

LGTM!


public class DukeTest {

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

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

@@ -0,0 +1,12 @@
package duke;

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

System.out.println(String.format(" %d. %s", (i + 1), item.toString()));
}
}
} else if (parsedInput.equals("done")) {

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.
Copy link

@ramapriyan912001 ramapriyan912001 left a comment

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;

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 + ")";

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 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";
}
}

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!

} else {
Event e = new Event(splitString[2], splitString[3]);
if (splitString[1].equals("1")) {
e.markAsDone();

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?

* @param input user input
* @return updated task list
*/
public String run(Storage storage, String input) throws DukeException {

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?

}
}

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

Choose a reason for hiding this comment

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

Well modularised! Great job!

2. [T][ ] read book
3. [D][X] return book (by: Sunday)
4. [E][ ] project meeting (at: Monday 2-4pm)
____________________________________________________________

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