Skip to content

Commit

Permalink
Merge branch 'branch-Level-10'
Browse files Browse the repository at this point in the history
  • Loading branch information
dlathyun committed Sep 6, 2023
2 parents dac359d + bc4afde commit 39010dd
Show file tree
Hide file tree
Showing 27 changed files with 387 additions and 31 deletions.
24 changes: 23 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ plugins {
id 'application'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'checkstyle'
id 'org.openjfx.javafxplugin' version '0.0.13'
}

javafx {
version = "17.0.8"
modules = [ 'javafx.controls' ]
}

checkstyle {
Expand All @@ -16,8 +22,24 @@ repositories {
dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0'

String javaFxVersion = '17.0.8'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux'
}


test {
useJUnitPlatform()

Expand All @@ -33,7 +55,7 @@ test {
}

application {
mainClass.set("duke.Duke")
mainClass.set("duke.gui.Launcher")
}

shadowJar {
Expand Down
3 changes: 2 additions & 1 deletion data/savedtask.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
E / [ ] / hw / 2022-08-05 21:29/ 2022-08-07 12:11

T / [ ] / lecture
30 changes: 23 additions & 7 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@
import duke.task.TaskList;
import duke.ui.Ui;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;


/**
* Main class of Kora Chatbot Program.
*/
public class Duke {

private TaskList taskList;
private Storage storage;
private Ui ui;
private boolean isExit = false;




/**
* Class constructor of Duke.
*
* @param filePath path of file in user's hard disk.
*/
public Duke(String filePath) {
public Duke() {
ui = new Ui();
storage = new Storage(filePath);
storage = new Storage("./data/savedtask.txt");
taskList = new TaskList();
try {
storage.loadTask(taskList);
Expand All @@ -40,7 +46,7 @@ public Duke(String filePath) {
public Command getResponse(String userInput) {
try {
Command command = Parser.parse(userInput);
command.execute(taskList);
command.execute(taskList, storage);
command.printOutput(command.getCommandMessage());
return command;
} catch (KoraException e) {
Expand All @@ -66,12 +72,22 @@ public void run() {
ui.closeScanner();
}

public String getGreeting() {
return ui.getGreetMessage();
}


/**
* Runs the main programme.
* @param args The command-line arguments
*/
public static void main(String[] args) {
Duke kora = new Duke("./data/savedtask.txt");
kora.run();
try {
Duke kora = new Duke();
kora.run();
} catch (Exception e) {
System.out.println("haha,,");
}

}
}
3 changes: 2 additions & 1 deletion src/main/java/duke/command/ByeCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package duke.command;

import duke.storage.Storage;
import duke.task.TaskList;

public class ByeCommand extends Command {
Expand All @@ -12,7 +13,7 @@ public String getCommandMessage() {
return commandMessage;
}
@Override
public void execute(TaskList taskList) {
public void execute(TaskList taskList, Storage storage) {

commandMessage = "Byebye. See you again!";
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.command;

import duke.exception.KoraException;
import duke.storage.Storage;
import duke.task.TaskList;

/**
Expand Down Expand Up @@ -34,7 +35,7 @@ public void printOutput(String output) {
* @param taskList List with tasks.
* @throws KoraException From its child class.
*/
public abstract void execute(TaskList taskList) throws KoraException;
public abstract void execute(TaskList taskList, Storage storage) throws KoraException;

/**
* Returns false for all the commands except ByeCommand.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/duke/command/DeadlineCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.command;

import duke.exception.KoraException;
import duke.storage.Storage;
import duke.task.Deadline;
import duke.task.Task;
import duke.task.TaskList;
Expand All @@ -25,9 +26,10 @@ public String getCommandMessage() {
}

@Override
public void execute(TaskList taskList) throws KoraException {
public void execute(TaskList taskList, Storage storage) throws KoraException {
Task currentTask = new Deadline(taskDetails, timeDetails);
taskList.addTask(currentTask);
storage.saveTask(taskList);
commandMessage = "Okay! I have added this task" + "\n"
+ currentTask.toString() + "\n"
+ String.format("Now you have %d tasks!", taskList.getLength());
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package duke.command;

import duke.exception.KoraException;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;

Expand All @@ -17,10 +19,11 @@ public String getCommandMessage() {
}

@Override
public void execute(TaskList taskList) {
public void execute(TaskList taskList, Storage storage) throws KoraException {
Task currentTask = taskList.getTask(taskIndex);
String taskDetails = currentTask.toString();
taskList.removeTask(taskIndex);
storage.saveTask(taskList);
commandMessage = "Okay. I have removed this task" + "\n"
+ taskDetails + "\n" + String.format("Now you have %d tasks!", taskList.getLength());
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/duke/command/EventCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.command;

import duke.exception.KoraException;
import duke.storage.Storage;
import duke.task.Event;
import duke.task.Task;
import duke.task.TaskList;
Expand Down Expand Up @@ -30,9 +31,10 @@ public String getCommandMessage() {
}

@Override
public void execute(TaskList taskList) throws KoraException {
public void execute(TaskList taskList, Storage storage) throws KoraException {
currentTask = new Event(taskDetails, startTimeDetails, endTimeDetails);
taskList.addTask(currentTask);
storage.saveTask(taskList);
commandMessage = "Okay! I have added this task" + "\n"
+ currentTask.toString() + "\n"
+ String.format("Now you have %d tasks!", taskList.getLength());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/duke/command/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.command;

import duke.exception.KoraException;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;

Expand All @@ -22,7 +23,7 @@ public String getCommandMessage() {
}

@Override
public void execute(TaskList taskList) throws KoraException {
public void execute(TaskList taskList, Storage storage) throws KoraException {
int taskListSize = taskList.getLength();
for (int i = 0; i < taskListSize; i++) {
Task task = taskList.getTask(i + 1);
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/duke/command/InvalidCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package duke.command;

import duke.storage.Storage;
import duke.task.TaskList;

public class InvalidCommand extends Command {
private String commandMessage = "";
public InvalidCommand() {
}

@Override
public String getCommandMessage() {
return commandMessage;
}

@Override
public void execute(TaskList taskList, Storage storage) {

commandMessage = "I do not understand";
}
}
3 changes: 2 additions & 1 deletion src/main/java/duke/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package duke.command;

import duke.storage.Storage;
import duke.task.TaskList;

public class ListCommand extends Command {
Expand All @@ -14,7 +15,7 @@ public String getCommandMessage() {
}

@Override
public void execute(TaskList taskList) {
public void execute(TaskList taskList, Storage storage) {
if (taskList.getLength() == 0) {
commandMessage = "Wow! You have no tasks!";
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/duke/command/MarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package duke.command;

import duke.exception.KoraException;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;

Expand All @@ -18,9 +20,10 @@ public String getCommandMessage() {
}

@Override
public void execute(TaskList taskList) {
public void execute(TaskList taskList, Storage storage) throws KoraException {
Task currentTask = taskList.getTask(taskIndex);
currentTask.setMarked();
storage.saveTask(taskList);
commandMessage = "Wow you are done!" + "\n" + currentTask.toString();
}
}
4 changes: 3 additions & 1 deletion src/main/java/duke/command/ToDoCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.command;

import duke.exception.KoraException;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;
import duke.task.ToDo;
Expand All @@ -23,9 +24,10 @@ public String getCommandMessage() {
}

@Override
public void execute(TaskList taskList) {
public void execute(TaskList taskList, Storage storage) throws KoraException {
Task currentTask = new ToDo(taskDetails);
taskList.addTask(currentTask);
storage.saveTask(taskList);
commandMessage = "Okay! I have added this task" + "\n"
+ currentTask.toString() + "\n" + String.format("Now you have %d tasks!", taskList.getLength());
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/duke/command/UnmarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package duke.command;

import duke.exception.KoraException;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;

Expand All @@ -18,9 +20,10 @@ public String getCommandMessage() {
}

@Override
public void execute(TaskList taskList) {
public void execute(TaskList taskList, Storage storage) throws KoraException {
Task currentTask = taskList.getTask(taskIndex);
currentTask.setUnmarked();
storage.saveTask(taskList);
commandMessage = "Wow you are not done!" + "\n" + currentTask.toString();
}
}
Loading

0 comments on commit 39010dd

Please sign in to comment.