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

[Weiye] iP #295

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

[Weiye] iP #295

wants to merge 44 commits into from

Conversation

TeddYE
Copy link

@TeddYE TeddYE commented Jan 29, 2022

No description provided.

Let's implement a skeletal version of Duke that starts by greeting
the user, simply echoes commands entered by the user, and exits when
the user types bye.
Let's add the ability to store whatever text entered by the user
and display them back to the user when requested.
Let's,
* move the conditional break in the infinite loop into the loop
condition
* remove String.format()
Lets,
* add Task class to represent tasks
* add the ability to mark tasks as done and the ability to change
the status back to not done
As there are multiple types of tasks that have some similarity
between them, implement classes Todo, Deadline and Event classes
to inherit from a Task class.

Let's,
* add support for tracking three types of task
Use the input/output redirection technique to semi-automate the
testing of Duke.
Teach Duke to deal with errors such as incorrect inputs entered by
the user.

Let's
* add DukeException class
Let's
* Add support for deleting tasks from the list
Let's:
* use enum for types of tasks
@TeddYE TeddYE changed the title [Weiye] ip [Weiye] iP Jan 29, 2022
TeddYE and others added 16 commits January 30, 2022 22:51
Let's:
* add abstract class for different commands
Let's:
* add Storage class to facilitate reading and writing of list to file
Teach duke to understand date and time.

Let's
* update due date and event time to LocalDateTime instead of String
Implement level-8 functionalities
Let's:
* add TaskList class
* add Ui class
Add JavaDoc comments to the code
# Conflicts:
#	src/main/META-INF/MANIFEST.MF
Let's:
* add CFind class to handle the search function
* add appropriate response after the search is done
Implement Level-9 functionalities
Copy link

@hieunm1821 hieunm1821 left a comment

Choose a reason for hiding this comment

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

Overall, I found your code easy to read. However, there are a few minor coding standard. Just a few nits to fix.

this.parser = new Parser();
}

public void run() throws DukeException{

Choose a reason for hiding this comment

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

I think it should be a white space before the open curly bracket. I noticed the same issue in several other places too.

import java.util.ArrayList;

public class TaskList {
private ArrayList<Task> Tasks;

Choose a reason for hiding this comment

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

I think the variable name should be in camelCase. I suggest it should be tasks

import main.duke.Ui;
import main.duke.enums.CommandType;

public class CBye extends Command{

Choose a reason for hiding this comment

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

Should the name of class be CommandBye? I think it is more meaningful. Similar with other command names.

this.findString = findString;
}

public String getFindString() { return this.findString; }

Choose a reason for hiding this comment

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

I suggest follow EgyptianStyle when we make a function which has one line only. I noticed the same issue in several other places too.

Comment on lines 24 to 119
switch (userCommand) {
case "bye":
newCommand = new CBye();
break;
case "list":
newCommand = new CList();
break;
case "mark":
try {
int markIndex = Integer.parseInt(inputArray[1]) - 1;
newCommand = new CMark(markIndex);
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Please specify the task you wish to mark.");
} catch (NumberFormatException e) {
throw new DukeException("Invalid index format.");
}
break;
case "unmark":
try {
int unmarkIndex = Integer.parseInt(inputArray[1]) - 1;
newCommand = new CUnmark(unmarkIndex);
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Please specify the task you wish to unmark.");
} catch (NumberFormatException e) {
throw new DukeException("Invalid index format.");
}
break;
case "delete":
try {
int deleteIndex = Integer.parseInt(inputArray[1]) - 1;
newCommand = new CDelete(deleteIndex);
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Please specify the task you wish to delete.");
} catch (NumberFormatException e) {
throw new DukeException("Invalid index format.");
}
break;
case "todo":
String todoDescription = String.join(" ",
Arrays.copyOfRange(inputArray, 1, inputArray.length));
if (todoDescription.equals("")) {
throw new DukeException("Please specify the description of the todo task.");
}
newCommand = new CTodo(todoDescription);
break;
case "deadline":
if (!userInput.contains("/by")) {
throw new DukeException("Please specify the due date using the /by keyword.");
} else {
try {
int byIndex = Arrays.asList(inputArray).indexOf("/by");
String deadlineDescription = String.join(" ",
Arrays.copyOfRange(inputArray, 1, byIndex));
String dueDate = String.join(" ",
Arrays.copyOfRange(inputArray, byIndex + 1, inputArray.length));
LocalDateTime.parse(dueDate, DateTimeFormatter.ofPattern("yyyy-MM-dd kkmm"));
// check if the date and time input is in the right format
if (deadlineDescription.equals("") || dueDate.equals("")) {
throw new DukeException("Please specify the description/due date of the deadline task.");
}
newCommand = new CDeadline(deadlineDescription, dueDate);
} catch (DateTimeParseException e){
throw new DukeException("Please provide the date time in this format YYYY-MM-DD 0000");
}
}
break;
case "event":
if (!userInput.contains("/at")) {
throw new DukeException("Please specify the date time using the /at keyword.");
} else {
try {
int byIndex = Arrays.asList(inputArray).indexOf("/at");
String eventDescription = String.join(" ",
Arrays.copyOfRange(inputArray, 1, byIndex));
String dateTime = String.join(" ",
Arrays.copyOfRange(inputArray, byIndex + 1, inputArray.length));
LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd kkmm"));
// check if the date and time input is in the right format
if (eventDescription.equals("") || dateTime.equals("")) {
throw new DukeException("Please specify the description/date time of the event task.");
}
newCommand = new CEvent(eventDescription, dateTime);
} catch (DateTimeParseException e){
throw new DukeException("Please provide the date time in this format YYYY-MM-DD 0000");
}
}
break;
case "find":
String findString = String.join(" ",
Arrays.copyOfRange(inputArray, 1, inputArray.length));
newCommand = new CFind(findString);
break;
default:
throw new DukeException("Sorry. I do not understand your input.");
}
return newCommand;

Choose a reason for hiding this comment

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

I think there is no indentation for case clauses. I suggest you change the setting in the IDE.


import main.duke.enums.TaskType;

public class ToDo extends Task{

Choose a reason for hiding this comment

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

Should the class name Todo? 🤔

Copy link

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

String userCommand = inputArray[0];
Command newCommand;

switch (userCommand) {

Choose a reason for hiding this comment

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

there should not be an indentation for case clauses to follow the coding standards

TeddYE and others added 17 commits February 9, 2022 15:35
Implement Level-10 functionalities
Improve code quality based on Code Quality topics
Added cloning function for the tasks so that the previous state of
the tasks list can be saved.

Stack is used to store the previous state of the tasks list.

Unifying all those duplicated code improves the code quality.

As a step towards such unification, let's extract those duplicated
code blocks into separate methods in their respective classes.
Doing so will make the subsequent unification easier.
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.

3 participants