Skip to content

Commit

Permalink
Merge branch 'branch-B-Reminders'
Browse files Browse the repository at this point in the history
Add BCD extension.
  • Loading branch information
Diwu-Yi committed Sep 9, 2020
2 parents cbd5ace + 96b4322 commit c6f1c5e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 9 deletions.
2 changes: 1 addition & 1 deletion data/duke.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[T][✘] ask [T][✘] ask [D][✘] ask /by
[T][✘] ask [T][✘] ask [D][✘] be /by
8 changes: 8 additions & 0 deletions src/main/java/DateAndTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public DateAndTime(String dateAndTime) {

}

public LocalDate getDate(){
return this.date;
}

public LocalTime getTime(){
return this.time;
}

/**
* Overridden toString() method to print out the desired format of date and time.
*
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Deadline class is a subclass of Task which holds information for this type of tasks with
* a date and time (which is the deadline :) ).
*/
public class Deadline extends Task {
public class Deadline extends Task implements Comparable<Deadline>{

protected DateAndTime by;

Expand Down Expand Up @@ -40,4 +40,20 @@ public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}

/**
* Overridden compareTo method to compare urgency in date and time for a deadline.
* @param another the deadline task to compare with
* @return -1 if urgency of this deadline is higher, 0 if equal and 1 if urgency of another
* is higher
*/
@Override
public int compareTo(Deadline another){
if(!this.by.getDate().equals(another.by.getDate())){
return this.by.getDate().compareTo(another.by.getDate());
}

return this.by.getTime().compareTo(another.by.getTime());

}

}
5 changes: 5 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ public class Parser {
public final static String EMPTY = " ";
public final static String BYORAT = "/by ";
public final static String FIND = "find";
public final static String REMINDER = "reminder";

/**
* Constructs a Parser object to tackle the user inputs/commands.
*/
public Parser() {
}

public boolean isReminder(String input){
return input.contains(REMINDER);
}

public boolean isBye(String input) {
return input.equals(BYE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Task class is the subclass of Deadline, Event and Todo
* thus it holds common methods and constructors for these classes.
*/
public class Task {
public class Task{

protected String description;
protected boolean isDone;
Expand Down
50 changes: 44 additions & 6 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ private static String modify(String input, String type, DateAndTime byOrAt, Arra
*/
public static String read() {
String starter = "Here are the tasks in your list:\n" ;
String content = "";
StringBuilder content = new StringBuilder();
for (int i = 0; i < taskStorage.size(); i++) {
content = content + ((i + 1) + "." + taskStorage.get(i)) + "\n";
content.append(i + 1).append(".").append(taskStorage.get(i)).append("\n");
}
return starter + content;
}
Expand Down Expand Up @@ -86,17 +86,55 @@ public static String delete(int ref) {
public static String find(String feature) {

String starter = "Here are the matching tasks in your list:\n";
String content = "";
StringBuilder content = new StringBuilder();

for (Task task : TaskList.taskStorage) {
if (task.description.contains(feature)) {
content = content + (task) + "\n";
content.append(task).append("\n");
}
}

return starter + content;

}

/**
*
* @return
*/
public static String remind(){

ArrayList<Deadline> mostUrgent = new ArrayList<>(0);

for(Task task : TaskList.taskStorage){

if(task instanceof Deadline){

if(mostUrgent.isEmpty()){
mostUrgent.add((Deadline) task);
}

if(((Deadline) task).compareTo(mostUrgent.get(0)) < 0){
mostUrgent.remove(0);
mostUrgent.add((Deadline) task);
}

if(((Deadline) task).compareTo(mostUrgent.get(0)) == 0){
mostUrgent.add((Deadline) task);
}
}
}

if(mostUrgent.isEmpty()){
return ("Nice ! No upcoming deadline :). ");
}

String starter = "Your nearest deadline is: \n";
StringBuilder content = new StringBuilder();

for (Deadline deadline : mostUrgent) {
content.append(deadline).append("\n");
}

return starter + content;
}

}
8 changes: 8 additions & 0 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ private String dealDeadline(String input){

}

private String dealReminder(){
return TaskList.remind();
}

/**
* Workhorse of the project, deal with all possible instructions exactly as desired.
* @param input string text from the user
Expand All @@ -192,6 +196,10 @@ public String deal(String input) {

Storage.read();

if (parser.isReminder(input)){
return dealReminder();
}

if (parser.isBye(input)) {
return dealBye();
}
Expand Down

0 comments on commit c6f1c5e

Please sign in to comment.