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

[Ho Jing Yang Daniel] ip #60

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f9a4ecc
Level 1 Update
Bencotti Jan 19, 2020
6abab68
Add save feature and listing of all saved tasks.
Bencotti Jan 26, 2020
ba4ccbf
Revert "Add save feature and listing of all saved tasks."
Bencotti Jan 26, 2020
371a2de
Add save feature and listing of all recorded tasks
Bencotti Jan 26, 2020
8f57e03
Add logic for task completion and updated code to support Task class
Bencotti Jan 27, 2020
f6d7bf2
Update code to comply with CS2113 Java coding standards
Bencotti Jan 31, 2020
4ac1e1e
Change implementation of commands to follow assignment sample usage
Bencotti Feb 2, 2020
045d60e
Add support for tracking three types of tasks using inheritance
Bencotti Feb 2, 2020
5459ba6
Support display of event / deadline datetime
Bencotti Feb 3, 2020
97acd17
Automate text UI testing
Bencotti Feb 3, 2020
445c672
Improve code quality via refractoring and removal of magic numbers
Bencotti Feb 3, 2020
018f3cb
Update code to adhere closer to style guide after peer review
Bencotti Feb 13, 2020
184fec4
Update current exceptions to use proper Java built-in exceptions
Bencotti Feb 15, 2020
101781e
Refractor files into two packages - Exceptions or Duke
Bencotti Feb 15, 2020
b896d05
add exception for missing parameter and blank parameter for deadline …
Bencotti Feb 15, 2020
0f813e7
add exception handling for Event and Todo tasks
Bencotti Feb 15, 2020
e8f59a7
Merge branch 'branch-Level-5'
Bencotti Feb 15, 2020
ba35ca9
add delete function, remove dependancy on task counter variable and c…
Bencotti Feb 16, 2020
74e7f23
Add logic to write new tasks to file
Bencotti Feb 17, 2020
8418df9
update save logic, shift from task class to main
Bencotti Feb 17, 2020
ad533a9
add capability to read saved data from file and populate to list
Bencotti Feb 18, 2020
e9fb013
Merge branch 'branch-Level-7'
Bencotti Feb 18, 2020
b2d6d33
Merge branch 'branch-Level-6'
Bencotti Feb 18, 2020
f03c251
Fix list not updating after delete
Bencotti Feb 18, 2020
960018b
Add validation to check if data file exists before populating list
Bencotti Feb 18, 2020
4fe03b1
update git ignore file
Bencotti Feb 18, 2020
727b86d
Remove unused libries and tidy code
Bencotti Feb 23, 2020
4490216
Reractor methods into corresponding classes
Bencotti Feb 24, 2020
0e7ec06
Alter logical flow of code to use more objects
Bencotti Feb 26, 2020
0bfbddf
Convert task date from string to LocalTime
Bencotti Feb 27, 2020
4d8d986
Add exception handling for new datetime format
Bencotti Feb 27, 2020
f3468be
Add search feature via given keyword
Bencotti Feb 28, 2020
c9416ac
Add Javadoc
Bencotti Mar 1, 2020
72b98b6
Merge branch 'master' into branch-Level-8
Bencotti Mar 1, 2020
900134e
Merge remote-tracking branch 'origin/branch-Level-8'
Bencotti Mar 1, 2020
2c3a26c
Merge branch 'master' into branch-Level-9
Bencotti Mar 1, 2020
721d902
Merge branch 'master' into A-JavaDoc
Bencotti Mar 1, 2020
c013b71
Merge pull request #2 from Bencotti/branch-Level-9
Bencotti Mar 1, 2020
21db93a
Merge branch 'master' into A-JavaDoc
Bencotti Mar 1, 2020
a413c5b
Merge pull request #3 from Bencotti/A-JavaDoc
Bencotti Mar 1, 2020
0211ada
Resolve merge conflicts
Bencotti Mar 1, 2020
423172a
Add user guide
Bencotti Mar 1, 2020
d6e3556
Set theme jekyll-theme-cayman
Bencotti Mar 1, 2020
5f1babf
Set theme jekyll-theme-slate
Bencotti Mar 1, 2020
5d9a84f
Set theme jekyll-theme-slate
Bencotti Mar 1, 2020
a715778
Set theme jekyll-theme-cayman
Bencotti Mar 1, 2020
211d022
Edit code to adhere closer to style guide
Bencotti Mar 2, 2020
179fa3a
Merge branch 'master' of https://github.com/Bencotti/duke
Bencotti Mar 2, 2020
f25466a
Remove html tags from readme
Bencotti Mar 2, 2020
3983f5a
Fix README not displaying properly
Bencotti Mar 3, 2020
db1b11b
Fix REDAME not displaying "List"
Bencotti Mar 3, 2020
da193d5
Fix point 5 an 6 not displaying properly
Bencotti Mar 3, 2020
fcb06d4
Fix item 2 in README not displaying
Bencotti Mar 3, 2020
187b2a7
Fix README Item 3.1 not displaying properly
Bencotti Mar 3, 2020
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
Binary file added src/main/java/Deadline.class
Binary file not shown.
35 changes: 35 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class Deadline extends Task {

private String date;

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

public void setDate(String date) {
this.date = date;
}

public String getDate() {
return date;
}

@Override
public String getTaskType() {
return "D";
}

@Override
public void printAddDetails(int taskCounter) {
System.out.println("The following task has been added:\n[" + getTaskType() +"][" + super.getStatusIcon() + "] " + super.description + " (by: " + date + ")\n");
System.out.println("You've got " + taskCounter + " task(s) in the list!\n");
}

@Override
public void printListDetails(int count) {
System.out.println("["+ getTaskType() + "][" + super.getStatusIcon() + "] " + count + ". " + super.description + " (by: " + date + ")");
}

Choose a reason for hiding this comment

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

Possible redundant blank lines?


}
Binary file added src/main/java/Duke.class
Binary file not shown.
174 changes: 168 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,172 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Duke {

public static final int LENGTH_DEADLINE = 9;
public static final int LENGTH_EVENT = 6;
public static final int LENGTH_TODO = 5;
public static final int SIZE_DONE_COMMAND = 2;

Choose a reason for hiding this comment

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

Good job factoring out the constants!


public static void getDateTime() {
LocalDateTime myDateObj = LocalDateTime.now();
DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
String formattedDate = myDateObj.format(myFormatObj);
System.out.println(formattedDate);
}

public static void completeTask(ArrayList<Task> tasks, int taskIndex) {
taskIndex--; // index starts from 0, unlike listing number
if ( (taskIndex < tasks.size()) || (taskIndex > 0)) { // check if out of bounce

Choose a reason for hiding this comment

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

Minor typo: bounce -> bound

Choose a reason for hiding this comment

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

There is a coding standard violation that between the first two barcekets, there should be no space.

Task currentTask = tasks.get(taskIndex);
if (currentTask.getStatus()) { // check if already completed
System.out.println("Task already completed!\n");
} else {
currentTask.markAsDone();
System.out.println("Nice! I've marked this task as done:");
System.out.println( "["+ currentTask.getTaskType() + "][" + currentTask.getStatusIcon() + "] " + currentTask.getDescription() + "\n");

Choose a reason for hiding this comment

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

This line is a little bit too long. Maybe you can split this line into two rows.

}
} else {
System.out.println("Error: No such index in use\n");

Choose a reason for hiding this comment

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

Nice to take corner cases into account by specifying what to do when the task index is out of bound!

}
}

public static void printList(ArrayList<Task> tasks) {
int count = 1;
System.out.println("Listing tasks below:");

if (tasks.isEmpty()) {
System.out.println("No tasks at the moment!");
} else {
for (Task currentTask : tasks) {
currentTask.printListDetails(count);
count++;
}
}
System.out.println("");
}

public static void printHelp() {

Choose a reason for hiding this comment

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

Great idea to provide a guide to help users understand how to use your bot :D

System.out.println("Commands: ");
System.out.println("List: lists all recorded tasks \nusage: list\n");
System.out.println("Done: mark task as completed \nusage: done <task number>\n");
System.out.println("Todo: Tasks without date/time \nUsage: todo <task> \n(Avoid using other keywords as the first word)\n");

Choose a reason for hiding this comment

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

You can consider to make this string into constant if you are going to use it for mutiple times.This can improve the readibility of the code.

System.out.println("Event: Event including date/time \nUsage: event <task> /<date> \n(Avoid using other keywords as the first word)\n");
System.out.println("Deadline: Tasks including date/time \nUsage: deadline <task> /<date> \n(Avoid using other keywords as the first word)\n");
System.out.println("");
}

private static void printWelcomeMessage() {
String logo = " ,--, ,---, .--.--. ,---,\n"
+ ",--.'| ,`--.' | / / '. ' .' \\\n"
+ "| | : | : : | : /`. / / ; '.\n"
+ ": : ' : | ' ; | |--` : : \\\n"
+ "| ' | | : | | : ;_ : | /\\ \\\n"
+ "' | | ' ' ; \\ \\ `. | : ' ;. :\n"
+ "| | : | | | `----. \\ | | ;/ \\ \\\n"
+ "' : |__ ' : ; __ \\ \\ | ' : | \\ \\ ,'\n"
+ "| | '.'| | | ' / /`--' / | | ' '--'\n"
+ "; : ; ' : | '--'. / | : :\n"
+ "| , / ; |.' `--'---' | | ,'\n"
+ "---`-' '---' `--''\n";

System.out.println("\n" + logo + "\nYour Lifestyle Scheduling Assistant\n");
System.out.println("type \"help\" for list of commands");
System.out.println("____________________________________________________________\n");

Choose a reason for hiding this comment

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

If we print this long line mutiple times, we can make it a constant.

System.out.println("Everyday is a sunny day!");
/*
System.out.println("____________________________________________________________\n\nCurrent time: ");
getDateTime(); // due to testing purposes, will fail when coming timestamps
*/
System.out.println("____________________________________________________________");
}

public static void addDeadline(ArrayList<Task> tasks, String taskDescription, int taskCounter) {
try {
String itemName = taskDescription.substring(LENGTH_DEADLINE);
String[] words = itemName.split("/");
Task newTask = new Deadline(words[0].trim(), words[1].trim());
tasks.add(newTask);
newTask.printAddDetails(taskCounter);
} catch (Exception e) {
System.out.println("Please input the date using the specified format");
taskCounter--;
}
}

public static void addEvent(ArrayList<Task> tasks, String taskDescription, int taskCounter) {
try {
String itemName = taskDescription.substring(LENGTH_EVENT);
String[] words = itemName.split("/");
Task newTask = new Event(words[0].trim(), words[1].trim());
tasks.add(newTask);
newTask.printAddDetails(taskCounter);
} catch (Exception e) {
System.out.println("Please input the date using the specified format");
taskCounter--;
}
}

public static void addTodo(ArrayList<Task> tasks, String taskDescription, int taskCounter) {
String itemName = taskDescription.substring(LENGTH_TODO);
Task newTask = new ToDo(itemName.trim());
tasks.add(newTask);
newTask.printAddDetails(taskCounter);
}


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

printWelcomeMessage();

ArrayList<Task> tasks = new ArrayList<Task>();
int taskCounter = 0;

Scanner input = new Scanner(System.in);
String userCommand = input.nextLine();

while (!userCommand.equals("bye")){
String[] words = userCommand.split(" ");
int wordLength = words.length;
switch (words[0]) {
case "list":
printList(tasks);
break;
case "done":
if (wordLength != SIZE_DONE_COMMAND) {
System.out.println("Wrong format for command \"done\"");
break;
}
try {
int index = Integer.parseInt(words[1]);
completeTask(tasks, index);
} catch (Exception e) {
System.out.println("Please input a valid number\n");
}
break;

Choose a reason for hiding this comment

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

Inside the case "done": we can add a new function which extract these codes. It is not a coding standard violation, i am just commmenting to make your switch cases much cleaner.

case "help":
printHelp();
break;
case "todo":
taskCounter++;
addTodo(tasks, userCommand, taskCounter);
break;
case "event":
taskCounter++;
addEvent(tasks, userCommand, taskCounter);
break;
case "deadline":
taskCounter++;
addDeadline(tasks, userCommand, taskCounter);
break;
default:
System.out.println("Please add the task type\n");
}
// end of current listening loop, preparing next command
userCommand = input.nextLine();
}
System.out.println("LISA: Bye, hope to see you again!");
}
}
Binary file added src/main/java/Event.class
Binary file not shown.
33 changes: 33 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class Event extends Task {

private String date;

public void setDate(String date) {
this.date = date;
}

public String getDate() {
return date;
}

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

@Override
public String getTaskType(){
return "E";
}

@Override
public void printAddDetails(int taskCounter) {
System.out.println("The following task has been added:\n[" + getTaskType() +"][" + getStatusIcon() + "] " + description + " (at: " + date + ")\n");
System.out.println("You've got " + taskCounter + " task(s) in the list!\n");
}

@Override
public void printListDetails(int count) {
System.out.println("["+ getTaskType() + "][" + super.getStatusIcon() + "] " + count + ". " + description + " (by: " + date + ")");
}
}
Binary file added src/main/java/Task.class
Binary file not shown.
39 changes: 39 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
public class Task {
protected String description;
protected boolean isDone;

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

public boolean getStatus() {
return isDone;
}

public String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols
}

public String getDescription() {
return description;
}

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

public String getTaskType() {
return null;
}

public void printAddDetails(int taskCounter) {

Choose a reason for hiding this comment

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

Consider refactoring the printAddDetails() function so that you don't need to duplicate part of the print statement in the child classes

System.out.println("The following task has been added:\n[" + getTaskType() +"][" + getStatusIcon() + "] " + getDescription());

Choose a reason for hiding this comment

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

Please pay attention to line length. Try to keep line length shorter than 110 characters (soft limit). If the line exceeds the limit, use line wrapping at appropriate places of the line.

System.out.println("\nYou've got " + taskCounter + " task(s) in the list!\n");
}

public void printListDetails(int taskCounter) {
Bencotti marked this conversation as resolved.
Show resolved Hide resolved
System.out.println("["+ getTaskType() + "][" + getStatusIcon() + "] " + taskCounter + ". " + getDescription());
}

}
Binary file added src/main/java/ToDo.class
Binary file not shown.
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 {

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

@Override
public String getTaskType(){
return "T";

Choose a reason for hiding this comment

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

Consider making T a constant

Copy link
Author

Choose a reason for hiding this comment

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

Good suggestion!

}

}
50 changes: 50 additions & 0 deletions text-ui-test/ACTUAL.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

,--, ,---, .--.--. ,---,
,--.'| ,`--.' | / / '. ' .' \
| | : | : : | : /`. / / ; '.
: : ' : | ' ; | |--` : : \
| ' | | : | | : ;_ : | /\ \
' | | ' ' ; \ \ `. | : ' ;. :
| | : | | | `----. \ | | ;/ \ \
' : |__ ' : ; __ \ \ | ' : | \ \ ,'
| | '.'| | | ' / /`--' / | | ' '--'
; : ; ' : | '--'. / | : :
| , / ; |.' `--'---' | | ,'
---`-' '---' `--''

Your Lifestyle Scheduling Assistant

type "help" for list of commands
____________________________________________________________

Everyday is a sunny day!
____________________________________________________________
The following task has been added:
[T][?] add pie crust
Bencotti marked this conversation as resolved.
Show resolved Hide resolved

You've got 1 task(s) in the list!

The following task has been added:
[D][?] complete homework (by: now)

You've got 2 task(s) in the list!

The following task has been added:
[E][?] tutorial (at: Tuesday 2pm)

You've got 3 task(s) in the list!

Listing tasks below:
[T][?] 1. add pie crust
[D][?] 2. complete homework (by: now)
[E][?] 3. tutorial (by: Tuesday 2pm)

Nice! I've marked this task as done:
[D][?] complete homework

Listing tasks below:
[T][?] 1. add pie crust
[D][?] 2. complete homework (by: now)
[E][?] 3. tutorial (by: Tuesday 2pm)

LISA: Bye, hope to see you again!
Loading