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

Added recurring tasks #15

Closed
wants to merge 12 commits into from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ bin/
#data files from program
/data.txt/
data.txt
/recurringData.txt/
recurringData.txt
58 changes: 51 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CustomExceptions.DukeException;
import Enums.ExceptionType;
import Enums.Tasktype;
import Enums.RecurTaskType;
import Enums.TaskType;
import Model_Classes.*;
import Operations.*;

Expand All @@ -15,7 +16,7 @@ public class Duke {
private Storage storage;
private TaskList taskList;
private Parser parser;

private RecurHandler recurHandler;
/**
* Constructor of a Duke class. Creates all necessary objects and collections for Duke to run
* Also loads the ArrayList of tasks from the data.txt file
Expand All @@ -26,22 +27,34 @@ public Duke() {
storage = new Storage();
parser = new Parser();
try {
taskList = new TaskList(storage.loadFile());
taskList = new TaskList(storage.loadFile("data.txt"));
} catch (DukeException e) {
ui.showLoadError();
ArrayList<Task> emptyList = new ArrayList<>();
taskList = new TaskList(emptyList);
}
recurHandler = new RecurHandler(taskList);
if (recurHandler.checkRecurrence(taskList)) {
ui.showChangeInTaskList();
taskList.list();
}

}

/**
* Deals with the operation flow of Duke.
*/
public void run() {
boolean isExit = false;
boolean isExitRecur = false;
while (!isExit) {
String command = parser.getCommand();
Tasktype type = Tasktype.valueOf(command);
TaskType type;
try {
type = TaskType.valueOf(command);
} catch (IllegalArgumentException e) {
type = TaskType.others;
}
switch (type) {
case list :
ui.showList();
Expand All @@ -51,12 +64,11 @@ public void run() {
case bye :
isExit = true;
try {
storage.writeFile(taskList.currentList());
ui.showBye();
storage.writeFile(TaskList.currentList(), "data.txt");
} catch (DukeException e) {
ui.showWriteError();
ui.showBye();
}
ui.showBye();
break;

case done :
Expand Down Expand Up @@ -121,6 +133,38 @@ public void run() {
}
break;

case recur:
ui.promptRecurringActions();
while (!isExitRecur) {
String temp = parser.getCommand();
RecurTaskType recurType;
try {
recurType = RecurTaskType.valueOf(temp);
} catch (IllegalArgumentException e) {
recurType = RecurTaskType.others;
}
switch (recurType) {
case list:
recurHandler.listRecurring();
break;
case find:
recurHandler.findRecurring(parser.getKey());
break;
case exit:
isExitRecur = true;
ui.showExit();
break;
case add:
recurHandler.addBasedOnOperation();
break;
default:
ui.showCommandError();
break;
}
}
isExitRecur = false;
break;

default:
ui.showCommandError();
break;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/Enums/RecurTaskType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Enums;

public enum RecurTaskType {
list, find, others, add, exit
}
5 changes: 5 additions & 0 deletions src/main/java/Enums/RecurrenceScheduleType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Enums;

public enum RecurrenceScheduleType {
day, week, month
}
5 changes: 5 additions & 0 deletions src/main/java/Enums/SaveType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Enums;

public enum SaveType {
T, E, D, empty
}
5 changes: 0 additions & 5 deletions src/main/java/Enums/Savetype.java

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/java/Enums/TaskType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Enums;

public enum TaskType {
list, bye, find, done , delete, todo, deadline, other, event, recur, timer, snooze, others
}
5 changes: 0 additions & 5 deletions src/main/java/Enums/Tasktype.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/Model_Classes/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public Event(String description, Date at) {
public String toString() {
return "[E]" + super.toString() + " (on: " + at + ")";
}

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

import java.util.Date;

public class RecurringDeadline extends Deadline {
private String recurrence;
/**
* Constructor for the Deadline object.
* Takes in inputs for description and date/time the tasks should be done by.
*
* @param description Description of the task
* @param by The time the tasks should be done by.
*/
public RecurringDeadline(String description, Date by, String recurrence) {
super(description, by);
this.recurrence = recurrence;
}

@Override
public String toString() {
return super.toString() + " (R: " + recurrence + ")";
}
}
23 changes: 23 additions & 0 deletions src/main/java/Model_Classes/RecurringEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Model_Classes;

import java.util.Date;

public class RecurringEvent extends Event {
private String recurrence;
/**
* Constructor for Event object
* Takes in inputs for description of the event and the time the event occurs
*
* @param description Description of the event
* @param at Time the event happens
*/
public RecurringEvent(String description, Date at, String recurrence) {
super(description, at);
this.recurrence = recurrence;
}

@Override
public String toString() {
return super.toString() + " (R: " + recurrence + ")";
}
}
19 changes: 19 additions & 0 deletions src/main/java/Model_Classes/RecurringToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Model_Classes;

public class RecurringToDo extends ToDo {
private String recurrence;
/**
* Constructor of the class. Takes in the description of the task
*
* @param description Description of the task.
*/
public RecurringToDo(String description, String recurrence) {
super(description);
this.recurrence = recurrence;
}

@Override
public String toString() {
return super.toString() + " (R: " + recurrence + ")";
}
}
16 changes: 16 additions & 0 deletions src/main/java/Model_Classes/Task.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package Model_Classes;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
* Parent class for all other types of tasks
*/
public class Task{
private String description;
private boolean isDone;
private String created;

/**
* Constructor for the task object. takes in the description of the task
Expand All @@ -14,6 +19,13 @@ public class Task{
public Task(String description) {
this.description = description;
this.isDone = false;
DateTimeFormatter dateTimeFormatterNow = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
LocalDateTime now = LocalDateTime.now();
this.created = now.format(dateTimeFormatterNow);
}

public String getCreated() {
return this.created;
}

/**
Expand Down Expand Up @@ -48,6 +60,10 @@ public void setDone() {
isDone = true;
}

public void setNotDone() {
isDone = false;
}

/**
* Returns both the status icon and the description of the task.
* @return
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/Operations/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ public String getKey() {
String key = scanner.nextLine().toLowerCase();
return key;
}

public String getRecurrence() {
return scanner.nextLine().trim().toLowerCase();
}
}
Loading