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

[Varun] iP #198

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4a2729a
Add Greet
21varun12 Aug 26, 2021
b1017c9
Add Echo
21varun12 Aug 26, 2021
b8e223e
Add add, list
21varun12 Aug 26, 2021
3d06235
Add mark as done
21varun12 Aug 26, 2021
012b539
Comply with coding standard
21varun12 Aug 26, 2021
e4341c7
Add todo
21varun12 Sep 2, 2021
965a166
Refactor code
21varun12 Sep 2, 2021
b1c2436
Add deadline
21varun12 Sep 2, 2021
82d95e3
Add event
21varun12 Sep 2, 2021
afaf67b
Update TaskManager
21varun12 Sep 2, 2021
f0e08de
Refactor code
21varun12 Sep 2, 2021
152cfe6
Add exception classes
21varun12 Sep 9, 2021
a7b694f
Add exception handling
21varun12 Sep 9, 2021
8460d3f
Merge branch 'branch-Level-5'
21varun12 Sep 9, 2021
f7d89c2
Refactor commands
flerovious Sep 19, 2021
d97147d
Refactor with packages
flerovious Sep 19, 2021
1cb044c
Add delete command
flerovious Sep 19, 2021
7599173
Add save to local storage feature
flerovious Sep 20, 2021
4d48ad1
Merge remote-tracking branch 'origin/branch-Level-6'
flerovious Sep 20, 2021
ec66276
Merge remote-tracking branch 'origin/branch-Level-7'
flerovious Sep 20, 2021
2072337
Fix bugs with delete command
flerovious Sep 20, 2021
b0e98c2
Add JavaDocs
flerovious Sep 30, 2021
ee08d39
Add Ui class for user interactions
flerovious Sep 30, 2021
603a718
Refactor TaskList
flerovious Sep 30, 2021
ea0d5eb
Refactor Parser
flerovious Sep 30, 2021
7753232
Add LocalDate to Deadline and Event
flerovious Sep 30, 2021
133254d
Update InvalidCommand
flerovious Sep 30, 2021
8eac149
Add find command
flerovious Sep 30, 2021
59cc549
Merge pull request #1 from flerovious/branch-Level-8
flerovious Sep 30, 2021
4cdedaa
Merge branch 'master' into branch-Level-9
flerovious Sep 30, 2021
4e4d246
Fix import bug
flerovious Sep 30, 2021
dd2db1b
Merge pull request #2 from flerovious/branch-Level-9
flerovious Sep 30, 2021
29af211
Add JavaDocs
flerovious Sep 30, 2021
4a13fca
Refactor code to follow coding standard
flerovious Sep 30, 2021
70533ff
Add JavaDoc for Task
flerovious Sep 30, 2021
881d2d4
Merge branch 'master' into branch-A-JavaDoc
flerovious Sep 30, 2021
371f144
Merge pull request #3 from flerovious/branch-A-JavaDoc
flerovious Sep 30, 2021
b50c692
Add help command
flerovious Oct 1, 2021
5f4d0b3
Update User Guide
flerovious Oct 1, 2021
ffcec7a
Set theme jekyll-theme-cayman
flerovious Oct 1, 2021
53714ec
Set theme jekyll-theme-slate
flerovious Oct 1, 2021
ee1cd58
Set theme jekyll-theme-cayman
flerovious Oct 1, 2021
a87690f
Set theme jekyll-theme-hacker
flerovious Oct 1, 2021
244f594
Set theme jekyll-theme-cayman
flerovious Oct 1, 2021
d326977
Set theme jekyll-theme-minimal
flerovious Oct 1, 2021
a067104
Fix table rendering
flerovious Oct 1, 2021
dc92544
Fix table rendering
flerovious Oct 1, 2021
97b015f
Set theme jekyll-theme-cayman
flerovious Oct 1, 2021
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
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadline extends Task{

Choose a reason for hiding this comment

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

Perhaps there should be a space before the bracket? Similar for other classes.

Suggested change
public class Deadline extends Task{
public class Deadline extends Task {

private static String SYMBOL = "D";
Copy link

Choose a reason for hiding this comment

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

Perhaps this should be a final variable as I presume the SYMBOL is supposed to be a fixed constant

Choose a reason for hiding this comment

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

@arvejw is correct, as seen in the coding standards or code quality guidelines. The final keyword is to indicate that the String SYMBOL will never change. You can take a look at all constants and make sure they adhere to this.

private String dueDate;

public Deadline(String name, String dueDate) {
super(name);
this.dueDate = dueDate;
}

@Override
public String toString() {
return "[" + SYMBOL + "]" + super.toString() + " (by: " + dueDate + ")";
}
}
60 changes: 54 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,58 @@
import java.util.Scanner;

public class Duke {
public static String EXIT_CMD = "bye";
Copy link

Choose a reason for hiding this comment

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

Good use of constants.

public static String LIST_CMD = "list";
public static String DONE_CMD = "done";
public static String TODO_CMD = "todo";
public static String DEADLINE_CMD = "deadline";
public static String EVENT_CMD = "event";
Copy link

Choose a reason for hiding this comment

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

Perhaps you should make these variables final variables as well. From the naming convention used I am assuming you intend for these to be constants, but I may be misunderstanding something.

Choose a reason for hiding this comment

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

Perhaps these commands being grouped together could have a common prefix? Following coding standards:

Associated constants should have a common prefix.

Suggested change
public static String EXIT_CMD = "bye";
public static String LIST_CMD = "list";
public static String DONE_CMD = "done";
public static String TODO_CMD = "todo";
public static String DEADLINE_CMD = "deadline";
public static String EVENT_CMD = "event";
public static final String CMD_EXIT = "bye";
public static final String CMD_LIST = "list";
public static final String CMD_DONE = "done";
public static final String CMD_TODO = "todo";
public static final String CMD_DEADLINE = "deadline";
public static final String CMD_EVENT = "event";


public static void main(String[] args) {

Choose a reason for hiding this comment

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

Perhaps this method is too long? You can consider putting the logic in a separate class.

String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
greetUserOnStart();
Scanner input = new Scanner(System.in);

while (true) {
String command = input.nextLine();

// parse and handle commands
Copy link

Choose a reason for hiding this comment

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

Do you think you can put this logic in a different method?

if (command.equals(EXIT_CMD)) {
Copy link

Choose a reason for hiding this comment

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

I like the use of constants here! Makes it clear and easy to change

Copy link

Choose a reason for hiding this comment

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

As pointed out by others, very nice intuitive way of managing the various commands as the reader easily understands what command each code block carries out

break;
} else if (command.equals(LIST_CMD)) {
TaskManager.listTasks();
} else if (command.startsWith(DONE_CMD)) {
String parsedInput = command.split(" ")[1];
int taskNo = Integer.parseInt(parsedInput);
TaskManager.markTaskNoAsDone(taskNo - 1);
Copy link

Choose a reason for hiding this comment

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

Perhaps you might consider extracting out the execution of the commands into their own separate method

Copy link

Choose a reason for hiding this comment

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

Variable could be better named for less ambiguity. Overall good adherence to coding standard!

} else if (command.startsWith(TODO_CMD)) {
String parsedInput = command.replaceFirst(TODO_CMD, "");
String todo = parsedInput.strip();
TaskManager.addTodo(todo);
} else if (command.startsWith(DEADLINE_CMD)) {
String [] parsedInput = command.replaceFirst(DEADLINE_CMD, "").split("/by ");
String deadlineTitle = parsedInput[0].strip();
String deadlineDue = parsedInput[1].strip();
TaskManager.addDeadline(deadlineTitle, deadlineDue);
} else if (command.startsWith(EVENT_CMD)) {
String [] parsedInput = command.replaceFirst(EVENT_CMD, "").split("/at ");
Copy link

Choose a reason for hiding this comment

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

Plural form should be used on names representing a collection of objects.

Choose a reason for hiding this comment

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

@yzhedwin is correct, following coding standards.

String eventTitle = parsedInput[0].strip();
String eventTime = parsedInput[1].strip();
TaskManager.addEvent(eventTitle, eventTime);
} else {
// handle invalid command
Copy link

Choose a reason for hiding this comment

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

good indentation of comment

Copy link

Choose a reason for hiding this comment

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

This comment is helpful :)

System.out.println("Invalid command! Please enter a valid command");
}
}

Choose a reason for hiding this comment

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

maybe you could try to refactor the code to avoid long methods( above 30 LOC)


greetUserOnEnd();
}

public static void greetUserOnStart() {
System.out.println("Hello! I'm Duke");
System.out.println("What can I do for you?");
}

public static void greetUserOnEnd() {
System.out.println("Bye. Hope to see you again soon!");
}
}
14 changes: 14 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Event extends Task{

Choose a reason for hiding this comment

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

Suggested change
public class Event extends Task{
public class Event extends Task {

private static String SYMBOL = "E";
Copy link

Choose a reason for hiding this comment

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

Could the name be more descriptive?

Copy link

@arvejw arvejw Sep 3, 2021

Choose a reason for hiding this comment

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

Similar to previous comments about constants, you can consider making this a final variable as its value should not be changing

private String timeslot;

public Event(String name, String timeslot) {
super(name);
this.timeslot = timeslot;
}

@Override
public String toString() {
return "[" + SYMBOL + "]" + super.toString() + " (at: " + timeslot + ")";
}
}
26 changes: 26 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Task {
final private String name;

Choose a reason for hiding this comment

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

Perhaps the modifiers could be in the standard order? Separately, you may also want to have a setName functionality in the future, so making name final may not be necessary.

Suggested change
final private String name;
private final String name;

private Boolean isDone;

public Task(String name) {
this.name = name;
this.isDone = false;
}

public String getName() {
return name;
}

public String getStatusIcon() {
return (isDone ? "X" : " ");
}

public void markAsDone() {
isDone = true;
}

@Override
public String toString() {
return "[" + getStatusIcon() + "] " + getName();
}
}
47 changes: 47 additions & 0 deletions src/main/java/TaskManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
public class TaskManager {
private static int taskNo = 0;
final private static int maxTasks = 100;
Copy link

Choose a reason for hiding this comment

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

Perhaps a more informative name would be maxTasksNo to keep in line with taskNo, or name those two constants such that they sound similar

Choose a reason for hiding this comment

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

Perhaps this should be uppercase, as it is a constant?

Suggested change
final private static int maxTasks = 100;
private static final int MAX_TASKS = 100;

final static Task[] tasks = new Task[maxTasks];

Choose a reason for hiding this comment

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

Perhaps this should be private, following the encapsulation paradigm of OOP?

Suggested change
final static Task[] tasks = new Task[maxTasks];
private static final Task[] tasks = new Task[MAX_TASKS];


static void addTask(Task task) {

Choose a reason for hiding this comment

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

Consider updating the modifiers for the methods in this class. The default scope of methods in Java is package-private. Having them be static may not be advantageous as well, which you may learn later on.

if (taskNo < maxTasks) {

Choose a reason for hiding this comment

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

You can consider making the happy path prominent here.

tasks[taskNo] = task;
taskNo++;

Copy link

Choose a reason for hiding this comment

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

I think don't really need a new line

System.out.print("Got it. I've added this task:\n");
System.out.printf(" %s\n", task);
System.out.printf("Now you have %d tasks in the list.\n", taskNo);
}
}

static void addTodo(String todoName) {
Todo todo = new Todo(todoName);
addTask(todo);
}

static void addDeadline(String deadlineName, String deadlineDue) {
Copy link

Choose a reason for hiding this comment

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

Perhaps for the second parameter, you can use the same name as in Deadline.java (in this case it is dueDate), or a similar one in style with deadlineName

Deadline deadline = new Deadline(deadlineName, deadlineDue);
addTask(deadline);
}

static void addEvent(String eventName, String eventTime) {
Event event = new Event(eventName, eventTime);
addTask(event);
}

Choose a reason for hiding this comment

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

good use of refactoring to split the subtasks creation into 3 functions

static void listTasks() {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < taskNo; ++i) {
Task task = tasks[i];
System.out.printf("%d. %s\n", i + 1, task);

Choose a reason for hiding this comment

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

This is not too big a deal (printf vs println), though you can consider simply sticking to print (not printf) as Java has its own handy toString methods that can convert Integer for you. I believe printf may be a habit from C.

Suggested change
System.out.printf("%d. %s\n", i + 1, task);
System.out.println((i + 1) + ". " + task);

}

Choose a reason for hiding this comment

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

should stick to using printf or println not both as it is confusing

}

static void markTaskNoAsDone(int taskNo) {
Task task = tasks[taskNo];
task.markAsDone();

System.out.println("Nice! I've marked this task as done:");
System.out.printf(" %s\n", task);
}
}
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 {
private static String SYMBOL = "T";

Choose a reason for hiding this comment

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

i dont think it is a constant name , just a variable name but im not sure


public Todo(String name) {
super(name);
}

@Override
public String toString() {
return "[" + SYMBOL + "]" + super.toString();
}
}