Skip to content

Commit 213bf79

Browse files
Fix Launcher bug and update gitignore file
1 parent 2ddc270 commit 213bf79

7 files changed

Lines changed: 38 additions & 21 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ bin/
1515

1616
/text-ui-test/ACTUAL.txt
1717
text-ui-test/EXPECTED-UNIX.TXT
18+
.classpath
19+
.project
20+
.settings/org.eclipse.buildship.core.prefs

saveFile.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
T @ 0 @ 123
2+
T @ 0 @ Aadgsadf
3+
T @ 0 @ caodihfsd
4+
T @ 0 @ fda8daf
5+
T @ 0 @ ughreugies

src/main/java/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
public class Main extends Application {
1414

15-
private MyDuke myDuke = new MyDuke("../data/saveFile.txt");
15+
private MyDuke myDuke = new MyDuke("saveFile.txt");
1616

1717
@Override
1818
public void start(Stage stage) {

src/main/java/myDuke/MyDuke.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void main(String[] args) {
5050
try {
5151
storage.saveToFile(tasks.getTaskList());
5252
} catch (IOException e) {
53-
String newDir = "../data/saveFile.txt";
53+
// String newDir = "../data/saveFile.txt";
5454
ui.printErrorMsg("Something went wrong: " + e.getMessage());
5555
}
5656
sc.close();
@@ -133,18 +133,9 @@ static void finderChecker(String[] inputArr) throws NoKeywordException {
133133

134134

135135
public String getResponse(String input) {
136-
MyDuke myDuke = new MyDuke(DATA_SAVE_FILE_DIR);
137136
ui.askForUserInput();
138-
139137
Parser parser = new Parser(input, storage, tasks, ui);
140-
141-
// try {
142-
// storage.saveToFile(tasks.getTaskList());
143-
// } catch (IOException e) {
144-
// String newDir = "../data/saveFile.txt";
145-
// ui.printErrorMsg("Something went wrong: " + e.getMessage());
146-
// }
147-
parser.handleInput();
138+
// parser.handleInput();
148139
return parser.handleInputStr();
149140
}
150141

src/main/java/myDuke/Parser.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package myDuke;
22

3+
import java.io.IOException;
34
import java.time.LocalDate;
45
import java.time.format.DateTimeParseException;
56
import java.util.ArrayList;
@@ -95,7 +96,7 @@ public void handleInput() {
9596
MyDuke.indexChecker(getParsedInput());
9697
int ref = Integer.parseInt(getParsedInput()[1]);
9798
Task toRemove = tasks.getTask(ref);
98-
tasks.deleteTask(ref - 1);
99+
tasks.deleteTask(ref);
99100
ui.printDeletedTaskAlert(toRemove.toString(), tasks.getTaskList().size());
100101
} catch (NoIndexException e) {
101102
ui.printErrorMsg(e.getMessage());
@@ -196,14 +197,15 @@ public String handleInputStr() {
196197
switch (getParsedInput()[0]) {
197198
case "list":
198199
int counter = 1;
199-
String[] tempArr = new String[100];
200+
List<String> tempArr = new ArrayList<>();
200201
if (tasks.getTaskList().isEmpty()) { // improved implementation in case list is empty, gives a clear output
201202
return ui.showListEmptyMsgStr();
202203
} else {
203204
for (Task t : tasks.getTaskList()) { // changed String s to Task t
204-
tempArr[counter - 1] = counter + ". " + t.toString();
205+
tempArr.add(counter + ". " + t.toString());
205206
counter++;
206207
}
208+
207209
return ui.printTasksInListStr(tempArr);
208210
}
209211
case "done":
@@ -226,7 +228,7 @@ public String handleInputStr() {
226228
MyDuke.indexChecker(getParsedInput());
227229
int ref = Integer.parseInt(getParsedInput()[1]);
228230
Task toRemove = tasks.getTask(ref);
229-
tasks.deleteTask(ref - 1);
231+
tasks.deleteTask(ref);
230232
return ui.printDeletedTaskAlertStr(toRemove.toString(), tasks.getTaskList().size());
231233
} catch (NoIndexException e) {
232234
return ui.printErrorMsgStr(e.getMessage());
@@ -307,6 +309,12 @@ public String handleInputStr() {
307309
return ui.printErrorMsgStr(e.getMessage());
308310
}
309311
case "bye":
312+
try {
313+
storage.saveToFile(tasks.getTaskList());
314+
} catch (IOException e) {
315+
// String newDir = "../data/saveFile.txt";
316+
ui.printErrorMsg("Something went wrong: " + e.getMessage());
317+
}
310318
return ui.showByeMsgStr();
311319
case "sort":
312320
Collections.sort(tasks.taskList, new TaskListComparator());

src/main/java/myDuke/Ui.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package myDuke;
22

3+
import java.util.List;
34
import java.util.Scanner;
45

56
/**
@@ -124,8 +125,8 @@ String printDoneTaskAlertStr(String completedTask) {
124125

125126
void printDeletedTaskAlert(String deletedTask, int numOfRemainingTasksInList) {
126127
print(new String[] {
127-
"ok i just help u deleted this task -- " + deletedTask,
128-
". now u got " + numOfRemainingTasksInList + " item(s) in your list ah"
128+
"Pai Kia Bot: ok i just help u deleted this task -- " + deletedTask + ". ",
129+
"now u got " + numOfRemainingTasksInList + " item(s) in your list ah"
129130
});
130131
}
131132

@@ -204,6 +205,15 @@ String printTasksInListStr(String[] tasksArr) {
204205
return str;
205206
}
206207

208+
String printTasksInListStr(List<String> tasksArr) {
209+
210+
String str = "";
211+
for (String s : tasksArr) {
212+
str += s + "\n";
213+
}
214+
return str;
215+
}
216+
207217
void printSearchResultList(String keyword, String[] tasksArr) {
208218
print("Paikia Bot: dis is your search result for '" + keyword + "'", tasksArr);
209219
}

src/main/resources/view/MainWindow.fxml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<?import javafx.scene.layout.AnchorPane?>
77
<?import javafx.scene.layout.VBox?>
88

9-
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="MainWindow">
9+
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="MainWindow">
1010
<children>
11-
<TextField fx:id="userInput" layoutY="558.0" onAction="#handleUserInput" prefHeight="41.0" prefWidth="324.0" AnchorPane.bottomAnchor="1.0" />
11+
<TextField fx:id="userInput" layoutY="558.0" onAction="#handleUserInput" prefHeight="41.0" prefWidth="324.0" promptText="Talk to me leh" AnchorPane.bottomAnchor="1.0" />
1212
<Button fx:id="sendButton" layoutX="324.0" layoutY="558.0" mnemonicParsing="false" onAction="#handleUserInput" prefHeight="41.0" prefWidth="76.0" text="Send" />
1313
<ScrollPane fx:id="scrollPane" hbarPolicy="NEVER" hvalue="1.0" prefHeight="557.0" prefWidth="400.0" vvalue="1.0">
1414
<content>
1515
<VBox fx:id="dialogContainer" prefHeight="552.0" prefWidth="388.0" />
1616
</content>
1717
</ScrollPane>
1818
</children>
19-
</AnchorPane>
19+
</AnchorPane>

0 commit comments

Comments
 (0)