Skip to content

[KristopherPTaslim] iP#287

Open
KristopherPTaslim wants to merge 39 commits into
nus-cs2103-AY2122S2:masterfrom
KristopherPTaslim:master
Open

[KristopherPTaslim] iP#287
KristopherPTaslim wants to merge 39 commits into
nus-cs2103-AY2122S2:masterfrom
KristopherPTaslim:master

Conversation

@KristopherPTaslim
Copy link
Copy Markdown

@KristopherPTaslim KristopherPTaslim commented Jan 28, 2022

DukePro

"Your mind is for having ideas, not holding them." - David Allen (source)

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

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

All you need to do is,

  1. download it from here
  2. double-click it.
  3. add your tasks
  4. let it manage your tasks for you 😉

And it is FREE!

Features:

  • Managing tasks
  • Managing deadlines (coming soon)
  • Reminders (coming soon

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

public class Main {
    public static void main(String[] args) {
        Application.launch(MainApp.class, args);
    }
}

Copy link
Copy Markdown

@pnutzz-0207 pnutzz-0207 left a comment

Choose a reason for hiding this comment

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

Overall you are following the coding standards, very good job! 💯 just a few minor mistakes made, after you change it, it'll all look good to me 👏

Comment thread src/main/java/Duke.java Outdated
Comment on lines +1 to +5
import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Following the coding standards, you might need to arrange the import statements into alphabetical order! :)
Same for some of the other classes that includes import statements.

Suggested change
import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.io.IOException;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Scanner;

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

class Duke {

public static void main(String[] args) 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.

You might need to leave a space after DukeException

Suggested change
public static void main(String[] args) throws DukeException{
public static void main(String[] args) throws DukeException {

Comment thread src/main/java/Duke.java Outdated
Comment on lines +11 to +12
FileClass fc = new FileClass(); //file class
String home = System.getProperty("user.home"); //home directory
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 how you make comments behind the lines! It makes the logic clear 😄

Comment thread src/main/java/Duke.java Outdated
String dateTime = input.substring(indexOfTime + deadlineCondition.length(), input.length()); // the date and time for by
//convert to the correct one
LocalDateTime deadlineTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm"));
String convertedTime = deadlineTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"));
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 how you name your variables :), it is very clear what they all do 👍

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

// Recording everything in the duke.txt
for (int i = 0; i < taskArray.size(); i++ ) {
Task tasks = taskArray.get(i);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since it is referring to just 1 task, will it be better to name this variable as 'task' instead of 'tasks'?

Copy link
Copy Markdown

@manu2002g manu2002g left a comment

Choose a reason for hiding this comment

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

Great code quality! The variable names used are all short and descriptive and help a lot to make the code easy to understand! 😄

Comment thread src/main/java/Duke.java Outdated
Comment on lines +99 to +109
int indexOfTime = input.indexOf(eventCondition); //to find /
String dateTime = input.substring(indexOfTime + eventCondition.length(), input.length()); // the date and time for by
//convert to the correct one
LocalDateTime eventTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm"));
String convertedTime = eventTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"));
String stringSliced = input.substring(6, indexOfTime); // after deadline
stringArray.add(stringSliced);
Event eventTask = new Event(stringSliced, convertedTime);
taskArray.add(eventTask);
String noOfTask = String.valueOf(taskArray.size());
System.out.println(messageTask + eventTask.toString() + "\n"
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 use of comments to clarify what each line is doing! Maybe you could also use a few blank lines to separate the code block into logical sections (such as formatting, processing and output.) The coding standard recommends that "Logical units within a block should be separated by one blank line."

Comment thread src/main/java/Duke.java Outdated
System.out.println(index + "." + taskArray.get(i));
}
}
} else if (checkType[0].equals("mark") || checkType[0].equals("unmark")) { //this is to check whether it goes through marking
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 think this line has more than the 120 character line limit allowed by the coding standard. Maybe you could add a line break to improve readability

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

try {
int index = Integer.parseInt(checkType[1]) - 1;
Task tasks = taskArray.get(index);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe change the name of this variable to task since it only refers to a single entry

Copy link
Copy Markdown

@kahleongq kahleongq left a comment

Choose a reason for hiding this comment

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

Overall you adhered mostly to the coding standards, keep it up!

Comment thread src/main/java/Parser.java Outdated
default:
ui.showDefaultMessage();
break;

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 you could remove the indentation for the case clauses to follow the coding standards

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Hi Kris! Code is generally well done, just keep in mind that it's best to break up code into smaller blocks for increased readability and to use more descriptive naming:)

Comment on lines +7 to +10
public Deadline(String description, String by) {
super(description);
this.by = 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 you could rename "by" to something more descriptive.

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

Comment thread src/main/java/duke/Duke.java Outdated
Parser parser = new Parser(taskList);

while (sc.hasNextLine()) {
parser.execute(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 you can change the name of the method since a parser is parsing an input

Suggested change
parser.execute(input);
parser.parseInput(input);

Comment thread src/main/java/duke/DukeException.java Outdated
Comment on lines +5 to +7
public DukeException(String Message) {
super(Message);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could add a more descriptive message to be stored within the DukeException class

Comment on lines +7 to +10
public Event(String description, String at) {
super(description);
this.at = 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.

Same thing with the deadline task

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

Comment on lines +17 to +125
switch (checkCase[0].toLowerCase()) {

case ("list"):
ui.showListMessage(taskList);
break;

case ("mark"):
try {
int index = Integer.parseInt(checkCase[1]) - 1;
Task tasks = taskList.getTaskArray().get(index);
System.out.println(tasks.marking(checkCase[0].toLowerCase()));
taskList.getTaskArray().set(index, tasks);
} catch (ArrayIndexOutOfBoundsException e) {
ui.showInvalidInput();
}
break;

case ("unmark"):
try {
int index = Integer.parseInt(checkCase[1]) - 1;
Task tasks = taskList.getTaskArray().get(index);
System.out.println(tasks.marking(checkCase[0].toLowerCase()));
taskList.getTaskArray().set(index, tasks);
} catch (ArrayIndexOutOfBoundsException e) {
ui.showInvalidInput();
}
break;

case ("todo"):

try {
String toDoCondition = "todo ";
int indexOfToDo = toDoCondition.length(); //to find todo
String stringSliced = input.substring(indexOfToDo,input.length());
Todo todoTask = new Todo(stringSliced);
taskList.addTask(todoTask);
String noOfTask = String.valueOf(taskList.getTaskArray().size());
ui.showAddedMessage(todoTask, noOfTask);
} catch (StringIndexOutOfBoundsException e) {
ui.showTodoError();
}
break;

case ("deadline"):

try {
String deadlineCondition = "/by ";
int indexOfTime = input.indexOf(deadlineCondition); //to find /
String dateTime = input.substring(indexOfTime + deadlineCondition.length(), input.length()); // the date and time for by
//convert to the correct one
LocalDateTime deadlineTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm"));
String convertedTime = deadlineTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"));
String stringSliced = input.substring(9, indexOfTime); // after deadline
Deadline deadlineTask = new Deadline(stringSliced, convertedTime);
taskList.addTask(deadlineTask);
String noOfTask = String.valueOf(taskList.getTaskArray().size());
ui.showAddedMessage(deadlineTask, noOfTask);
} catch (StringIndexOutOfBoundsException e) {
ui.showDeadlineError();
}
break;

case ("event"):

try {
String eventCondition = "/at ";
int indexOfTime = input.indexOf(eventCondition); //to find /
String dateTime = input.substring(indexOfTime + eventCondition.length(), input.length()); // the date and time for at
//convert to the correct one
LocalDateTime eventTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm"));
String convertedTime = eventTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"));
String stringSliced = input.substring(6, indexOfTime); // after deadline
Event eventTask = new Event(stringSliced, convertedTime);
taskList.addTask(eventTask);
String noOfTask = String.valueOf(taskList.getTaskArray().size());
ui.showAddedMessage(eventTask, noOfTask);

} catch (StringIndexOutOfBoundsException e) {
ui.showEventError();
}
break;

case("delete"):

try {
int index = Integer.parseInt(checkCase[1]) - 1;
Task task = taskList.getTaskArray().get(index);
taskList.deleteTask(index);
String noOfTask = String.valueOf(taskList.getTaskArray().size());
ui.showDeletedMessage(task, noOfTask);
} catch (ArrayIndexOutOfBoundsException e) {
ui.showDeleteError();
}
break;

case("bye"):
ui.showGoodbyeMessage();
break;

default:
ui.showDefaultMessage();
break;



}


}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apart from the coding standard violations, perhaps you can break up each case instruction into separate methods for increased readability?

For example:

public void delete() {
    try {
                    int index = Integer.parseInt(checkCase[1]) - 1;
                    Task task = taskList.getTaskArray().get(index);
                    taskList.deleteTask(index);
                    String noOfTask = String.valueOf(taskList.getTaskArray().size());
                    ui.showDeletedMessage(task, noOfTask);
                } catch (ArrayIndexOutOfBoundsException e) {
                    ui.showDeleteError();
                }
}

KristopherPTaslim and others added 13 commits February 14, 2022 16:46
The method execute() does not follow the coding standard due to its
length. There are common logic in the method which cause
code duplication.

Extracting this common logic allows the method to be significantly
shorter and the principle of SLAP to be followed. For example,
the method parseByCondition() and parseString() shows the
SLAP principle.
Assertions are required in order to check whether the code
is able to work.

Assertions allow assertion error to be thrown if some conditions
are not held properly. For example, implementing assertion task
cannot be null in the method showAddedMessage(Task task, String
noOfTask) will throw assertion error if the input of task is null.
Add assertions in some various points in code
Edit execute() method in Parser class to follow coding standard.
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.

4 participants