-
Notifications
You must be signed in to change notification settings - Fork 73
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
base: master
Are you sure you want to change the base?
Changes from 11 commits
f9a4ecc
6abab68
ba4ccbf
371a2de
8f57e03
f6d7bf2
4ac1e1e
045d60e
5459ba6
97acd17
445c672
018f3cb
184fec4
101781e
b896d05
0f813e7
e8f59a7
ba35ca9
74e7f23
8418df9
ad533a9
e9fb013
b2d6d33
f03c251
960018b
4fe03b1
727b86d
4490216
0e7ec06
0bfbddf
4d8d986
f3468be
c9416ac
72b98b6
900134e
2c3a26c
721d902
c013b71
21db93a
a413c5b
0211ada
423172a
d6e3556
5f1babf
5d9a84f
a715778
211d022
179fa3a
f25466a
3983f5a
db1b11b
da193d5
fcb06d4
187b2a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 + ")"); | ||
} | ||
|
||
|
||
} |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor typo: bounce -> bound There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!"); | ||
} | ||
} |
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 + ")"); | ||
} | ||
} |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider refactoring the |
||
System.out.println("The following task has been added:\n[" + getTaskType() +"][" + getStatusIcon() + "] " + getDescription()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
} | ||
|
||
} |
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion! |
||
} | ||
|
||
} |
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible redundant blank lines?