forked from nus-cs2103-AY2425S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create different task type subclasses to align towards the OOP standard
- Loading branch information
Showing
9 changed files
with
322 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,72 @@ | ||
package muller.task; | ||
|
||
public class DeadlineTask { | ||
import java.time.LocalDate; | ||
|
||
/** | ||
* Represents a task that has a deadline. | ||
*/ | ||
public class DeadlineTask extends Task { | ||
private LocalDate deadline; | ||
/** | ||
* Constructs a DeadlineTask object with the specified name and deadline date. | ||
* | ||
* @param name The name of the deadline task. | ||
* @param deadline The deadline date of the task. | ||
*/ | ||
public DeadlineTask(String name, LocalDate deadline) { | ||
super(name); | ||
this.deadline = deadline; | ||
this.type = "[D]"; | ||
} | ||
|
||
/** | ||
* Returns the deadline date of the task. | ||
* | ||
* @return The deadline date. | ||
*/ | ||
public LocalDate getDeadline() { | ||
return deadline; | ||
} | ||
|
||
/** | ||
* Checks if the task occurs on a specified date. | ||
* | ||
* @param date The date to check. | ||
* @return True if the task's deadline is on the specified date, false otherwise. | ||
*/ | ||
@Override | ||
public boolean isOnDate(LocalDate date) { | ||
return this.deadline.equals(date); | ||
} | ||
|
||
/** | ||
* Checks if the task is due within the next 3 days. | ||
* | ||
* @return True if the deadline is within the next 3 days, false otherwise. | ||
*/ | ||
@Override | ||
public boolean isDueSoon() { | ||
return deadline.isBefore(LocalDate.now().plusDays(3)) && deadline.isAfter(LocalDate.now()); | ||
} | ||
|
||
/** | ||
* Converts the DeadlineTask to a string format suitable for saving to a file. | ||
* | ||
* @return The string representation of the DeadlineTask for saving. | ||
*/ | ||
@Override | ||
public String convertToFileString() { | ||
return "D | " + (isDone() ? "1" : "0") + " | " + getName() + " | " + deadline.format(OUTPUT_DATE_FORMATTER); | ||
} | ||
|
||
/** | ||
* Returns a string representation of the task, including its deadline. | ||
* | ||
* @return A string representing the task and its deadline. | ||
*/ | ||
@Override | ||
public String toString() { | ||
return this.type + getDoneIcon() + " " + getName() + " (by: " + deadline.format(OUTPUT_DATE_FORMATTER) + ")"; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,87 @@ | ||
package muller.task; | ||
|
||
public class EventTask { | ||
import java.time.LocalDate; | ||
|
||
/** | ||
* Represents a task that occurs over a range of dates. | ||
*/ | ||
public class EventTask extends Task { | ||
private LocalDate startDate; | ||
private LocalDate endDate; | ||
|
||
/** | ||
* Constructs an EventTask object with the specified name, start date, and end date. | ||
* | ||
* @param name The name of the event task. | ||
* @param startDate The start date of the event. | ||
* @param endDate The end date of the event. | ||
*/ | ||
public EventTask(String name, LocalDate startDate, LocalDate endDate) { | ||
super(name); | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
this.type = "[E]"; | ||
} | ||
|
||
/** | ||
* Checks if the task occurs on a specified date. | ||
* | ||
* @param date The date to check. | ||
* @return True if the date is within the event's start and end dates, false otherwise. | ||
*/ | ||
@Override | ||
public boolean isOnDate(LocalDate date) { | ||
return !date.isBefore(startDate) && !date.isAfter(endDate); | ||
} | ||
|
||
/** | ||
* Checks if the event starts within the next 3 days. | ||
* | ||
* @return True if the start date is within the next 3 days, false otherwise. | ||
*/ | ||
@Override | ||
public boolean isDueSoon() { | ||
return startDate.isBefore(LocalDate.now().plusDays(3)) && startDate.isAfter(LocalDate.now()); | ||
} | ||
|
||
/** | ||
* Returns the start date of the task. | ||
* | ||
* @return The event start date. | ||
*/ | ||
public LocalDate getStartDate() { | ||
return startDate; | ||
} | ||
|
||
/** | ||
* Returns the start date of the task. | ||
* | ||
* @return The event start date. | ||
*/ | ||
public LocalDate getEndDate() { | ||
return endDate; | ||
} | ||
|
||
/** | ||
* Converts the EventTask to a string format suitable for saving to a file. | ||
* | ||
* @return The string representation of the EventTask for saving. | ||
*/ | ||
@Override | ||
public String convertToFileString() { | ||
return "E | " + (isDone() ? "1" : "0") + " | " + getName() + " | " + startDate.format(OUTPUT_DATE_FORMATTER) | ||
+ " | " + endDate.format(OUTPUT_DATE_FORMATTER); | ||
} | ||
|
||
/** | ||
* Returns a string representation of the task, including its start and end dates. | ||
* | ||
* @return A string representing the task and its date range. | ||
*/ | ||
@Override | ||
public String toString() { | ||
return this.type + getDoneIcon() + " " + getName() + " (from: " + startDate.format(OUTPUT_DATE_FORMATTER) | ||
+ " to: " + endDate.format(OUTPUT_DATE_FORMATTER) + ")"; | ||
} | ||
} | ||
|
Oops, something went wrong.