forked from nus-cs2103-AY1920S1/duke
-
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.
- Loading branch information
Showing
36 changed files
with
560 additions
and
161 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* Represents the Command for adding Tasks and its subclasses. | ||
* A subclass of Command. | ||
*/ | ||
public class AddDeadlineCommand extends Command { | ||
|
||
final String timePattern = "d MMMM yyyy, h:mma"; | ||
DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern(timePattern); | ||
|
||
/** | ||
* Overridden execute method from Command to add a Deadline object into the list of tasks. | ||
* It will throw an exception if the user inputs are unrecognisable for the | ||
* method to execute correctly. | ||
* | ||
* @param storage Storage object for saving purposes | ||
* @param tasks Contains the list of tasks | ||
* @param ui Holds Ui printing methods and user input field | ||
* @param input User input | ||
* @return Add Task Message | ||
* @throws DukeException If inputs are invalid and format of subsequent fields is wrong | ||
*/ | ||
@Override | ||
public String execute(Storage storage, TaskList tasks, Ui ui, String input) throws DukeException { | ||
String[] userWords; | ||
if (input.isEmpty()) { | ||
throw new DukeException("☹ OOPS!!! The description of a deadline cannot be empty."); | ||
} | ||
userWords = input.split("/by"); | ||
if (userWords.length == 1) { | ||
throw new DukeException("☹ OOPS!!! The date/time of a deadline cannot be empty or is wrongly typed."); | ||
} | ||
try { | ||
LocalDateTime dateObj = LocalDateTime.parse(userWords[1].trim(), | ||
DateTimeFormatter.ofPattern("d/MM/yyyy Hmm")); | ||
String date = dateObj.format(dateTimeFormat); | ||
return tasks.addTask(new Deadline(userWords[0].trim(), date)); | ||
} catch (DateTimeParseException e) { | ||
throw new DukeException("Could not recognise date and time. Please follow the format: dd/mm/yyyy HHmm."); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* Represents the Command for adding Tasks and its subclasses. | ||
* A subclass of Command. | ||
*/ | ||
public class AddEventCommand extends Command { | ||
|
||
/** | ||
* Overridden execute method from Command to add an Event object into the list of tasks. | ||
* It will throw an exception if the user inputs are unrecognisable for the | ||
* method to execute correctly. | ||
* | ||
* @param storage Storage object for saving purposes | ||
* @param tasks Contains the list of tasks | ||
* @param ui Holds Ui printing methods and user input field | ||
* @param input User input | ||
* @return Add Task Message | ||
* @throws DukeException If inputs are empty and format of subsequent fields is wrong | ||
*/ | ||
@Override | ||
public String execute(Storage storage, TaskList tasks, Ui ui, String input) throws DukeException { | ||
|
||
String[] userWords; | ||
if (input.isEmpty()) { | ||
throw new DukeException("☹ OOPS!!! The description of an event cannot be empty."); | ||
} | ||
userWords = input.split("/at"); | ||
if (userWords.length == 1) { | ||
throw new DukeException("☹ OOPS!!! The date/time of an event cannot be empty or is wrongly typed."); | ||
} | ||
return tasks.addTask(new Event(userWords[0].trim(), userWords[1].trim())); | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* Represents the Command for adding Tasks and its subclasses. | ||
* A subclass of Command. | ||
*/ | ||
public class AddToDoCommand extends Command { | ||
|
||
/** | ||
* Overridden execute method from Command to add a To Do object into the list of tasks. | ||
* It will throw an exception if the user inputs are unrecognisable for the | ||
* method to execute correctly. | ||
* | ||
* @param storage Storage object for saving purposes | ||
* @param tasks Contains the list of tasks | ||
* @param ui Holds Ui printing methods and user input field | ||
* @param input User input | ||
* @return Add Task Message | ||
* @throws DukeException If input is empty | ||
*/ | ||
@Override | ||
public String execute(Storage storage, TaskList tasks, Ui ui, String input) throws DukeException { | ||
if (input.isEmpty()) { | ||
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty."); | ||
} | ||
return tasks.addTask(new Task(input)); | ||
} | ||
} |
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
Oops, something went wrong.