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

[Aakansha Narain] iP #491

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
ff47a7a
Level-1
aakanshanarain Aug 16, 2021
7358409
Level-2
aakanshanarain Aug 16, 2021
3147541
Level-3
aakanshanarain Aug 16, 2021
5869554
Level-4
aakanshanarain Aug 17, 2021
9ff98b5
A-TextUiTesting
aakanshanarain Aug 17, 2021
abe05eb
Level-5
aakanshanarain Aug 18, 2021
afabe7d
Level-6
aakanshanarain Aug 18, 2021
a82ef81
Level-6
aakanshanarain Aug 18, 2021
1a56d9d
Add more OOP
aakanshanarain Aug 29, 2021
15af52e
Move classes to duke package
aakanshanarain Aug 29, 2021
feca504
Add Storage class
aakanshanarain Sep 15, 2021
e3694ff
Add JUnit Tests
aakanshanarain Sep 15, 2021
8c70f0d
Add JAR file
aakanshanarain Sep 15, 2021
edfb3f6
Add Javadocs to public methods
aakanshanarain Sep 15, 2021
257ac69
Tweak to comply with coding standards
aakanshanarain Sep 15, 2021
ab089f4
Add find command functionality
aakanshanarain Sep 17, 2021
fc54428
Merge branch 'branch-A-CodingStandard'
aakanshanarain Sep 17, 2021
3109605
Resolve conflicts while merging branch-Level-9
aakanshanarain Sep 17, 2021
acf0641
Merge remote-tracking branch 'origin/add-gradle-support' into branch-…
aakanshanarain Sep 17, 2021
98b0856
Add Gradle support to automate some build tasks
aakanshanarain Sep 17, 2021
20af5bb
Add GUI to Duke
aakanshanarain Sep 18, 2021
3c0c2b5
Add storage functionality to save tasklist
aakanshanarain Sep 18, 2021
7192bbb
Add date and time conversion for task inputs
aakanshanarain Sep 18, 2021
c37b6a3
Add more OOP
aakanshanarain Sep 18, 2021
4619db6
Add more JavaDocs and tweak coding style
aakanshanarain Sep 18, 2021
c228d14
Add assertions
aakanshanarain Sep 18, 2021
16385f3
Revert "Add assertions"
aakanshanarain Sep 18, 2021
94c3a0a
Add assertions
aakanshanarain Sep 18, 2021
9370619
Improve overall code quality: modify to adhere to SLAP and add better…
aakanshanarain Sep 18, 2021
6df5f8c
Merge pull request #2 from aakanshanarain/branch-A-Assertions
aakanshanarain Sep 18, 2021
227584f
Merge pull request #3 from aakanshanarain/branch-A-CodeQuality
aakanshanarain Sep 18, 2021
f576001
Add tagging functionality for tasks
aakanshanarain Sep 18, 2021
0f34752
Rectify problems with the GUI
aakanshanarain Sep 19, 2021
8a175e0
Add Ui.png
aakanshanarain Sep 19, 2021
c4e7b8f
Add User Guide
aakanshanarain Sep 19, 2021
4c29fb3
Change homepage screenshot for user guide
aakanshanarain Sep 19, 2021
e5d7624
Set theme jekyll-theme-minimal
aakanshanarain Sep 19, 2021
896873a
Set theme jekyll-theme-minimal
aakanshanarain Sep 19, 2021
7f2eaac
Set theme jekyll-theme-cayman
aakanshanarain Sep 19, 2021
3c4eac7
Set theme jekyll-theme-minimal
aakanshanarain Sep 19, 2021
1a66261
Add acknowledgments
aakanshanarain Sep 19, 2021
9163300
Merge branch 'master' of github.com:aakanshanarain/ip
aakanshanarain Sep 19, 2021
8e9ec2f
Tweak README.md
aakanshanarain Sep 19, 2021
6b49768
Update README.md
aakanshanarain Sep 19, 2021
b90d9b5
Set theme jekyll-theme-minimal
aakanshanarain Sep 19, 2021
52a8bb9
Update README.md
aakanshanarain Sep 19, 2021
43f2042
Update README.md
aakanshanarain Sep 19, 2021
9126f32
Tweak README.md to fix images and replace Ui.png
aakanshanarain Sep 20, 2021
f073024
Tweak README.md to fix Homepage image
aakanshanarain Sep 20, 2021
e696299
Update to help command for the GUI
aakanshanarain Sep 20, 2021
e65284f
Tweak Duke.java
aakanshanarain Sep 20, 2021
ca20ffe
Clean code by removing redundant methods and add more JavaDocs
aakanshanarain Sep 20, 2021
9ca2212
Delete tasks.txt
aakanshanarain Sep 20, 2021
dac5432
Fix issues with launching on Windows and Linux
aakanshanarain Sep 21, 2021
589e068
Refactor code in CommandHandler, Parser and Ui
aakanshanarain Sep 21, 2021
7fceaae
Update exceptions to be more comprehensive
aakanshanarain Sep 23, 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
66 changes: 60 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
//Solution below slightly adapted from https://github.com/Wincenttjoi/CS2103T-duke-chatbot/blob/master/src/main/java/duke/Duke.java

import duke.*;

Choose a reason for hiding this comment

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

Should you be including the individual packages here rather than a wildcard?


public class Duke {

Choose a reason for hiding this comment

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

You could also add some comments here! I think this would allow you to communicate your code effectively!


private Ui ui;
private TaskList taskList;
private boolean exit;

Choose a reason for hiding this comment

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

You could change this to a more boolean sounding name!


public Duke () {
this.ui = new Ui();
this.taskList = new TaskList();
exit = false;
}

public enum InputCommands {
bye, list, done, delete, todo, deadline, event

Choose a reason for hiding this comment

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

Since these are going to be unchanged, you could possibly rename to be capitalised? For example, BYE, LIST, DONE etc. However, i like the naming of the enum InputCommands here!

}

public void start () {

Choose a reason for hiding this comment

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

I think you do not need to add a space after the method name here! just start() would do

System.out.println(ui.greet());
while (!exit) {
try {
String userCommand = ui.echoCommand();

if (userCommand.equals("bye")) {
System.out.println(ui.exit());
exit = true;
} else if (userCommand.equals("list")) {
System.out.println(ui.retrieveList());
} else if (userCommand.startsWith("done")) {
InputHandler doneInputHandler = new DoneInput(ui, taskList);
System.out.println(doneInputHandler.handle(userCommand));
} else if (userCommand.startsWith("delete")) {
InputHandler deleteInputHandler = new DeleteInput(ui, taskList);
System.out.println(deleteInputHandler.handle(userCommand));
} else if (userCommand.startsWith("todo")) {
InputHandler todoInputHandler = new TodoInput(ui, taskList);
System.out.println(todoInputHandler.handle(userCommand));
} else if (userCommand.startsWith("deadline")) {
InputHandler deadlineInputHandler = new DeadlineInput(ui, taskList);
System.out.println(deadlineInputHandler.handle(userCommand));
} else if (userCommand.startsWith("event")) {
InputHandler eventInputHandler = new EventInput(ui, taskList);
System.out.println(eventInputHandler.handle(userCommand));
} else if (userCommand.equals("listInputs")) {
for (InputCommands inputs : InputCommands.values()) {
System.out.println(inputs);
}
}
else {
throw new UnknownInputException("error");
}
} catch (DukeException e) {
ui.getError(e.getMessage());
}
}
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
new Duke().start();

Choose a reason for hiding this comment

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

i think you could explicitly close Duke after this by adding a System.close() here!

}
}
16 changes: 16 additions & 0 deletions src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package duke;

public class Deadline extends Task {

protected String by;

Choose a reason for hiding this comment

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

i think this variable should be private even if it is only going to be accessed within the package! you could add a getter to retrieve this variable


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

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
24 changes: 24 additions & 0 deletions src/main/java/duke/DeadlineInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package duke;

import duke.Deadline;

public class DeadlineInput extends InputHandler {

public DeadlineInput(Ui ui, TaskList taskList) throws DukeException {
super(ui, taskList);
}

@Override

Choose a reason for hiding this comment

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

I think you could refactor your toString method here! or possibly store the instantiated objects as variables instead!

public String handle(String input) throws EmptyDescriptionException {
if (input.length() == 8) {
throw new EmptyDescriptionException("error" );
}
int charIndex = input.indexOf("/" );
int byIndex = charIndex + 4;
String by = input.substring(byIndex);
String task = input.substring(9, charIndex - 1);
Task deadlineTask = new Deadline(task, by);
taskList.add(deadlineTask);
return ui.addedTask(deadlineTask);
}
}
23 changes: 23 additions & 0 deletions src/main/java/duke/DeleteInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package duke;

public class DeleteInput extends InputHandler {

public DeleteInput(Ui ui, TaskList taskList) {
super(ui, taskList);
}

@Override
public String handle(String input) throws EmptyDescriptionException {
if (input.length() == 6) {

Choose a reason for hiding this comment

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

I'm not too sure whether i understand the reasoning behind using length() here. Could you comment on this?

throw new EmptyDescriptionException("error");
}

char taskIndex = input.charAt(7);

Choose a reason for hiding this comment

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

i like this separation of lines. allows me to understand the flow of logic slightly better.

int index = Integer.parseInt(String.valueOf(taskIndex));

Task taskAtIndex = taskList.getTask(index);

taskList.removeTask(index);
return ui.deletedTask(taskAtIndex);
}
}
24 changes: 24 additions & 0 deletions src/main/java/duke/DoneInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package duke;

public class DoneInput extends InputHandler {

public DoneInput(Ui ui, TaskList taskList) throws DukeException {
super(ui, taskList);
}

@Override
public String handle (String input) throws EmptyDescriptionException {
if (input.length() == 4) {
throw new EmptyDescriptionException("error");

Choose a reason for hiding this comment

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

I think it's great to have different Exceptions here! really improves the OO-ness of the project.

}

char taskIndex = input.charAt(5);

Choose a reason for hiding this comment

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

I think you could rename the variable here, to something like indexOfTask?

int index = Integer.parseInt(String.valueOf(taskIndex));

Task taskAtIndex = taskList.getTask(index);
taskAtIndex.markAsDone();

return ui.doneTask(taskAtIndex);
}

}
9 changes: 9 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package duke;

public class DukeException extends Exception{

public DukeException (String e) {
super(e);
}

}
8 changes: 8 additions & 0 deletions src/main/java/duke/EmptyDescriptionException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package duke;

public class EmptyDescriptionException extends DukeException{

public EmptyDescriptionException(String e) {
super("Error: The description of that command cannot be empty. Please enter a description.");
}
}
17 changes: 17 additions & 0 deletions src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package duke;

public class Event extends Task {

private String at;

Choose a reason for hiding this comment

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

You could remove the extra empty line


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

@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + at + ")";
}
}
27 changes: 27 additions & 0 deletions src/main/java/duke/EventInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package duke;

import duke.Event;

public class EventInput extends InputHandler {


public EventInput(Ui ui, TaskList taskList) throws DukeException {
super(ui, taskList);
}

public String handle(String input) throws EmptyDescriptionException {
if (input.length() == 5) {
throw new EmptyDescriptionException("error" );
}
int charIndex = input.indexOf("/" );
int atIndex = charIndex + 4;

Choose a reason for hiding this comment

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

I like how you named your variables here! (Easy to understand)


String at = input.substring(atIndex);
String task = input.substring(6, charIndex - 1);

Task eventTask = new Event(task, at);
taskList.add(eventTask);

return ui.addedTask(eventTask);
}
}
14 changes: 14 additions & 0 deletions src/main/java/duke/InputHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package duke;

public abstract class InputHandler {
protected Ui ui;
protected TaskList taskList;

Choose a reason for hiding this comment

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

You could add a line between? (To keep your coding style consistent, same thing with couple of other files)


public InputHandler(Ui ui, TaskList taskList) {
this.taskList = taskList;
this.ui = ui;
}

public abstract String handle(String input) throws EmptyDescriptionException;

}
25 changes: 25 additions & 0 deletions src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package duke;

public class Task {
protected String description;
protected boolean isDone;

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

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public void markAsDone () {
this.isDone = true;
}

@Override
public String toString () {
return "[" + getStatusIcon() + "] " + this.description;
}

}
28 changes: 28 additions & 0 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package duke;

import java.util.ArrayList;

public class TaskList {
private static ArrayList<Task> todoList;

Choose a reason for hiding this comment

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

You could rename this to tasks to keep it consistent with the coding standards provided by prof!

Choose a reason for hiding this comment

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

this could also be instance level (non-static) rather than class level! I think it would be easier to keep track of the collection this way.


public TaskList() {
todoList = new ArrayList<>();
}

public static ArrayList<Task> getTodoList () {
return todoList;
}

public void add (Task task) {

Choose a reason for hiding this comment

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

again, as with other lines of code, you could remove the space between the method name and parameter parentheses

todoList.add(task);
}

Choose a reason for hiding this comment

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

I like how you named your variables with verbs, easy to understand at one glance.


public Task getTask (int index) {
return todoList.get(index - 1);
}

public void removeTask (int index) {
todoList.remove(index - 1);
}

}
13 changes: 13 additions & 0 deletions src/main/java/duke/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke;

public class Todo extends Task {

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

@Override
public String toString() {
return "[T]" + super.toString();
}
}
20 changes: 20 additions & 0 deletions src/main/java/duke/TodoInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package duke;

public class TodoInput extends InputHandler {

public TodoInput(Ui ui, TaskList taskList) throws DukeException {
super(ui, taskList);
}

public String handle(String input) throws EmptyDescriptionException {
if (input.length() == 4) {
throw new EmptyDescriptionException("error");
}

String task = input.substring(5);
Task toDoTask = new Todo(task);

taskList.add(toDoTask);
return ui.addedTask(toDoTask);
}
}
61 changes: 61 additions & 0 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package duke;

import java.util.ArrayList;
import java.util.Scanner;

public class Ui {

private static final String GREET = "Hi there! My name's Duke, how can I help you today?";
private static final String EXIT = "Bye! See you next time!";

private Scanner sc;

public Ui() {
this.sc = new Scanner(System.in);
}

public String greet () {
return GREET;
}

public String exit () {
return EXIT;
}

public String echoCommand () {
return sc.nextLine();
}

public String retrieveList() {
ArrayList<Task> list = TaskList.getTodoList();
if (list.size() == 0) {
return "You currently have no tasks!";
} else {
String userList = "";
for (Task task : list) {
userList = userList + (list.indexOf(task) + 1) + ". " + task.toString() + "\n";
}
return "Here are the tasks in your list:\n" + userList;
}
}

public String addedTask(Task task) {
return String.format("Got it. I've added this task:\n %s\nNow you have %d tasks in the list.",
task.toString(), TaskList.getTodoList().size());
}

public String doneTask (Task task) {
return String.format("Nice! I've marked this task as done:\n %s", task.toString());
}

public String deletedTask(Task task) {
return String.format("Noted. I've removed this task:\n %s\nNow you have %d tasks in the list.",
task.toString(), TaskList.getTodoList().size());
}

public void getError(String e) {
System.out.println(e);
}


}
Loading