Skip to content

Commit

Permalink
Merge branch 'branch-Level-10'
Browse files Browse the repository at this point in the history
  • Loading branch information
gachia committed Sep 7, 2019
2 parents a7bc606 + decb740 commit 4af4a52
Show file tree
Hide file tree
Showing 36 changed files with 560 additions and 161 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Duke Increment | Tutorial
---------------|---------------
`A-Gradle` | [Gradle Tutorial](tutorials/gradleTutorial.md)
`A-TextUiTesting` | [Text UI Testing Tutorial](tutorials/textUiTestingTutorial.md)
`Level-10` | JavaFX tutorials:<br>→ [Part 1: Introduction to JavaFX][fx1]<br>→ [Part 2: Creating a GUI for Duke][fx2]<br>→ [Part 3: Interacting with the user][fx3]<br>→ [Part 4: Introduction to FXML][fx4]
`Level-10` | JavaFX tutorials:<br>→ [Part 1: Introduction to JavaFX][fx1]<br>→ [Part 2: Creating a Gui for Duke][fx2]<br>→ [Part 3: Interacting with the user][fx3]<br>→ [Part 4: Introduction to FXML][fx4]

[fx1]: <tutorials/javaFxTutorialPart1.md>
[fx2]: <tutorials/javaFxTutorialPart2.md>
Expand Down
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.7'
id 'application'
id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '5.1.0'
Expand All @@ -20,13 +21,18 @@ shadowJar {
archiveAppendix = null
}

group 'seedu.duke'
group 'duke'
version '0.1.0'

repositories {
mavenCentral()
}

javafx {
version = "11.0.2"
modules = [ 'javafx.controls', 'javafx.fxml']
}

test {
useJUnitPlatform()
}
Expand All @@ -37,5 +43,5 @@ run {

application {
// Change this to your main class.
mainClassName = "Duke"
mainClassName = "GUI"
}
79 changes: 0 additions & 79 deletions src/main/java/AddCommand.java

This file was deleted.

45 changes: 45 additions & 0 deletions src/main/java/AddDeadlineCommand.java
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.");
}
}
}
37 changes: 37 additions & 0 deletions src/main/java/AddEventCommand.java
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()));

}
}
30 changes: 30 additions & 0 deletions src/main/java/AddToDoCommand.java
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));
}
}
9 changes: 6 additions & 3 deletions src/main/java/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ public Command() {
/**
* Abstract method for the sub-classes of Command to use. This method will execute
* differently based on the sub-class called.
*
* @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 tasks Contains the list of tasks
* @param ui Holds Ui printing methods and user input field
* @param input User input
* @throws DukeException If there is an error
*/
abstract void execute(Storage storage, TaskList tasks, Ui ui) throws DukeException;
abstract String execute(Storage storage, TaskList tasks, Ui ui, String input) throws DukeException;

/**
* Returns boolean variable hasExit for checking exit status.
*
* @return hasExit boolean variable
*/
public boolean isExit() {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ public class Deadline extends Task {

/**
* Constructor to set the description of deadline and due date and time.
*
* @param desc The description of the Deadline
* @param by The due date and time of the Deadline
* @param by The due date and time of the Deadline
*/
public Deadline(String desc, String by) {
super(desc);
Expand All @@ -18,8 +19,9 @@ public Deadline(String desc, String by) {

/**
* Constructor with additional parameter to set its completion status.
* @param desc The description of the Deadline
* @param by The due date and time of the Deadline
*
* @param desc The description of the Deadline
* @param by The due date and time of the Deadline
* @param isDone The boolean variable to note if Deadline is completed
*/
public Deadline(String desc, String by, boolean isDone) {
Expand All @@ -30,6 +32,7 @@ public Deadline(String desc, String by, boolean isDone) {
/**
* Overridden writeFormat method to specify that it is a Deadline
* when saving the data.
*
* @return Format for saving data
*/
@Override
Expand All @@ -39,6 +42,7 @@ public String writeFormat() {

/**
* Overridden toString method to print out Deadline object.
*
* @return Printing format of Deadline
*/
@Override
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ public class DeleteCommand extends Command {
* Overridden execute method from Command to delete a Task object from the list of tasks.
* The method will check the user input for a valid index and deletes the selected
* Task object from the list. It will throw an exception if the index is invalid.
*
* @param storage Storage object for saving purposes
* @param tasks Contains the list of tasks
* @param ui Holds Ui printing methods and user input field
* @throws DukeException If deletion < 0 or > size of list
* @param tasks Contains the list of tasks
* @param ui Holds Ui printing methods and user input field
* @param input User input
* @return Delete Task Message
* @throws DukeException If deletion < 0 or > size of list or input is empty
*/
@Override
public void execute(Storage storage, TaskList tasks, Ui ui) throws DukeException {
int deletion = ui.readIndex();
public String execute(Storage storage, TaskList tasks, Ui ui, String input) throws DukeException {
if (input.isEmpty()) {
throw new DukeException("Please specify a task number.");
}
int deletion = Integer.parseInt(input);
if (deletion < 0 || deletion > tasks.getTaskList().size()) {
throw new DukeException("Task not found");
throw new DukeException("Task not found.");
}
tasks.deleteTask(deletion);
return tasks.deleteTask(deletion);
}
}
Loading

0 comments on commit 4af4a52

Please sign in to comment.