diff --git a/src/main/java/.idea/artifacts/main_jar.xml b/src/main/java/.idea/artifacts/main_jar.xml
new file mode 100644
index 000000000..b6c7247e3
--- /dev/null
+++ b/src/main/java/.idea/artifacts/main_jar.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/out/artifacts/main_jar
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/.idea/artifacts/main_jar2.xml b/src/main/java/.idea/artifacts/main_jar2.xml
new file mode 100644
index 000000000..b5c4b101a
--- /dev/null
+++ b/src/main/java/.idea/artifacts/main_jar2.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/out/artifacts/main_jar2
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/.idea/workspace.xml b/src/main/java/.idea/workspace.xml
index 6b952113d..4112028cf 100644
--- a/src/main/java/.idea/workspace.xml
+++ b/src/main/java/.idea/workspace.xml
@@ -1,11 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -30,7 +49,10 @@
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"kotlin-language-version-configured": "true",
- "last_opened_file_path": "C:/Users/nikhi/OneDrive/Desktop/untitled/src"
+ "last_opened_file_path": "C:/Users/nikhi/OneDrive/Desktop/untitled/src",
+ "project.structure.last.edited": "Artifacts",
+ "project.structure.proportion": "0.15",
+ "project.structure.side.proportion": "0.2"
}
}]]>
@@ -43,7 +65,7 @@
-
+
1709608220757
diff --git a/src/main/java/Command.java b/src/main/java/Command.java
index eb607ed44..79b1896ff 100644
--- a/src/main/java/Command.java
+++ b/src/main/java/Command.java
@@ -314,11 +314,13 @@ public FindCommand(String keyword) {
}
@Override
- public void execute(TaskList tasks, Ui ui, Storage storage) {
+ public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
ArrayList match_input = tasks.find_input(keyword);
if (match_input.isEmpty()) {
ui.error("There are no tasks found that match the keyword: " + keyword);
- } else {
+ } else if(keyword.isEmpty()){
+ throw new DukeException("Keyword is missing");
+ }else {
ui.line();
System.out.println("Here are the matching tasks in your list:");
for (int i = 0; i < match_input.size(); i++) {
diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java
index 71891ca38..cc6c670cd 100644
--- a/src/main/java/Duke.java
+++ b/src/main/java/Duke.java
@@ -52,6 +52,6 @@ public void run() {
* @param args Command-line arguments.
*/
public static void main(String[] args) {
- new Duke("out/tasks.txt").run();
+ new Duke("data/tasks.txt").run();
}
}
diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java
index 3ea747b3e..2c6830fcb 100644
--- a/src/main/java/Storage.java
+++ b/src/main/java/Storage.java
@@ -19,13 +19,28 @@ public Storage(String filePath) {
}
/**
- * Loads tasks from the file specified by the file path.
+ * Loads tasks from the specified file path. If the file or its parent directory does not exist,
+ * attempts to create them before reading tasks. Converts each line in the file to a Task object
+ * and adds it to the ArrayList of tasks.
*
* @return ArrayList of tasks loaded from the file.
- * @throws DukeException If an error occurs during file reading or if the file is not found.
+ * @throws DukeException If an error occurs during file creation, access, reading, or if the file is not found.
*/
public ArrayList load() throws DukeException {
ArrayList tasks = new ArrayList<>();
+ File file = new File(filePath);
+
+ try {
+ if (!file.exists()) {
+ File parentDir = file.getParentFile();
+ if (parentDir != null && !parentDir.exists()) {
+ parentDir.mkdirs();
+ }
+ file.createNewFile();
+ }
+ } catch (IOException e) {
+ throw new DukeException("Error creating or accessing the file: " + e.getMessage());
+ }
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
String line;
@@ -36,27 +51,43 @@ public ArrayList load() throws DukeException {
}
}
} catch (FileNotFoundException e) {
- throw new DukeException("File cannot be found.");
+ throw new DukeException("File not found: " + e.getMessage());
} catch (IOException e) {
- throw new DukeException("Error loading tasks from file.");
+ throw new DukeException("Error loading tasks from file: " + e.getMessage());
}
return tasks;
}
/**
- * Saves tasks to the file specified by the file path.
+ * Saves tasks to the specified file path. If the file or its parent directory does not exist,
+ * attempts to create them before saving the tasks.
*
* @param tasks ArrayList of tasks to be saved to the file.
- * @throws DukeException If an error occurs during file writing.
+ * @throws DukeException If an error occurs during file creation, access, or writing.
*/
public void save(ArrayList tasks) throws DukeException {
+ File file = new File(filePath);
+
+ try {
+ if (!file.exists()) {
+ File parentDir = file.getParentFile();
+ if (parentDir != null && !parentDir.exists()) {
+ parentDir.mkdirs();
+ }
+ file.createNewFile();
+ }
+ } catch (IOException e) {
+ throw new DukeException("Error creating or accessing the file: " + e.getMessage());
+ }
+
try (FileWriter writer = new FileWriter(filePath)) {
for (Task task : tasks) {
writer.write(task.toFileString() + "\n");
}
} catch (IOException e) {
- throw new DukeException("Error saving tasks to file.");
+ throw new DukeException("Error saving tasks to file: " + e.getMessage());
}
}
+
}
diff --git a/src/main/java/data/tasks.txt b/src/main/java/data/tasks.txt
new file mode 100644
index 000000000..aa9447aab
--- /dev/null
+++ b/src/main/java/data/tasks.txt
@@ -0,0 +1 @@
+T|assignment|0
diff --git a/src/main/java/out/artifacts/main_jar/main.jar b/src/main/java/out/artifacts/main_jar/main.jar
new file mode 100644
index 000000000..46603dfad
Binary files /dev/null and b/src/main/java/out/artifacts/main_jar/main.jar differ
diff --git a/src/main/java/out/artifacts/main_jar2/main.jar b/src/main/java/out/artifacts/main_jar2/main.jar
new file mode 100644
index 000000000..4b70dce36
Binary files /dev/null and b/src/main/java/out/artifacts/main_jar2/main.jar differ
diff --git a/src/main/java/out/production/main/.idea/artifacts/main_jar.xml b/src/main/java/out/production/main/.idea/artifacts/main_jar.xml
new file mode 100644
index 000000000..b6c7247e3
--- /dev/null
+++ b/src/main/java/out/production/main/.idea/artifacts/main_jar.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/out/artifacts/main_jar
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/out/production/main/.idea/artifacts/main_jar2.xml b/src/main/java/out/production/main/.idea/artifacts/main_jar2.xml
new file mode 100644
index 000000000..b5c4b101a
--- /dev/null
+++ b/src/main/java/out/production/main/.idea/artifacts/main_jar2.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/out/artifacts/main_jar2
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/out/production/main/.idea/workspace.xml b/src/main/java/out/production/main/.idea/workspace.xml
index 61e6393db..dfd305762 100644
--- a/src/main/java/out/production/main/.idea/workspace.xml
+++ b/src/main/java/out/production/main/.idea/workspace.xml
@@ -1,11 +1,21 @@
+
+
+
+
+
-
+
+
+
+
+
+
@@ -30,7 +40,10 @@
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"kotlin-language-version-configured": "true",
- "last_opened_file_path": "C:/Users/nikhi/OneDrive/Desktop/untitled/src"
+ "last_opened_file_path": "C:/Users/nikhi/OneDrive/Desktop/untitled/src",
+ "project.structure.last.edited": "Artifacts",
+ "project.structure.proportion": "0.15",
+ "project.structure.side.proportion": "0.2"
}
}]]>
@@ -43,7 +56,7 @@
-
+
1709608220757
diff --git a/src/main/java/out/production/main/Duke.class b/src/main/java/out/production/main/Duke.class
index b4c459430..691f4c0cf 100644
Binary files a/src/main/java/out/production/main/Duke.class and b/src/main/java/out/production/main/Duke.class differ
diff --git a/src/main/java/out/production/main/FindCommand.class b/src/main/java/out/production/main/FindCommand.class
index 0948d55dd..c2c1f2d4e 100644
Binary files a/src/main/java/out/production/main/FindCommand.class and b/src/main/java/out/production/main/FindCommand.class differ
diff --git a/src/main/java/out/production/main/Storage.class b/src/main/java/out/production/main/Storage.class
index 5964070a7..35eee1308 100644
Binary files a/src/main/java/out/production/main/Storage.class and b/src/main/java/out/production/main/Storage.class differ
diff --git a/src/main/java/out/production/main/data/tasks.txt b/src/main/java/out/production/main/data/tasks.txt
new file mode 100644
index 000000000..aa9447aab
--- /dev/null
+++ b/src/main/java/out/production/main/data/tasks.txt
@@ -0,0 +1 @@
+T|assignment|0