Skip to content

Commit 35eacaa

Browse files
committed
Add functionality to return the list of commands available if the user requires help
1 parent c9fe54d commit 35eacaa

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/main/java/duke/Duke.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ public class Duke {
44
private Storage storage;
55
private TaskList taskList;
66

7+
private enum Commands {
8+
LIST,
9+
TODO,
10+
DEADLINE,
11+
EVENT,
12+
BYE,
13+
FIND,
14+
DONE,
15+
DELETE
16+
}
17+
718

819
/**
920
* This constructor create a duke class after loading the tasks from a given file path
@@ -19,11 +30,21 @@ public Duke(String filePath) {
1930
taskList = new TaskList();
2031
}
2132
}
33+
public static String getHelp() {
34+
return "You have entered invalid commands! " +
35+
"Type 'help' if you are unsure of which commands I can understand:>";
36+
}
2237

2338

2439

2540
public String getResponse(String string) {
2641
switch (string.toLowerCase()) {
42+
case "help":
43+
String commandsList = "The commands that I can understand are: \n";
44+
for (Commands command : Commands.values()) {
45+
commandsList += command.toString() + "\n";
46+
}
47+
return commandsList;
2748
case "bye":
2849
try {
2950
storage.writeToFile(taskList, "./data/duke.txt");

src/main/java/duke/Parser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static Task parseFile(String data) throws DukeException {
3333
public static Pair parseInput(String input, TaskList tasks) {
3434
String[] inputSplit = input.split(" ");
3535
if (inputSplit.length < 2) {
36-
return new Pair(tasks, "You have entered invalid command!");
36+
return new Pair(tasks, Duke.getHelp());
3737
}
3838
Task task;
3939
String message;
@@ -44,7 +44,7 @@ public static Pair parseInput(String input, TaskList tasks) {
4444
TaskList result = tasks.findTask(keyword);
4545
message = "Here are the matching tasks in your list: \n";
4646
for (int i = 0; i < result.getSize(); i++) {
47-
message += result.getTask(i).toString();
47+
message += i+1 + ". " + result.getTask(i).toString();
4848
}
4949
break;
5050
case "done":
@@ -76,7 +76,7 @@ public static Pair parseInput(String input, TaskList tasks) {
7676
message = "Got it. I have added this task: \n" + task.toString();
7777
break;
7878
default:
79-
message = "You have entered invalid commands!";
79+
message = Duke.getHelp();
8080
}
8181

8282
return new Pair(tasks, message);

src/main/resources/view/DialogBox.fxml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
<?import javafx.scene.image.ImageView?>
66
<?import javafx.scene.layout.HBox?>
77

8-
<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="400.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
8+
<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308"
9+
maxWidth="1.7976931348623157E308" prefWidth="400.0" type="javafx.scene.layout.HBox"
10+
xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
911
<children>
1012
<Label fx:id="dialog" text="Label" wrapText="true" />
1113
<ImageView fx:id="displayPicture" fitHeight="99.0" fitWidth="99.0" pickOnBounds="true" preserveRatio="true" />

src/main/resources/view/MainWindow.fxml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
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="duke.MainWindow">
9+
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
10+
prefHeight="600.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.171"
11+
xmlns:fx="http://javafx.com/fxml/1" fx:controller="duke.MainWindow">
1012
<children>
1113
<TextField fx:id="userInput" layoutY="558.0" onAction="#handleUserInput" prefHeight="41.0" prefWidth="324.0" AnchorPane.bottomAnchor="1.0" />
1214
<Button fx:id="sendButton" layoutX="324.0" layoutY="558.0" mnemonicParsing="false" onAction="#handleUserInput" prefHeight="41.0" prefWidth="76.0" text="Send" />

0 commit comments

Comments
 (0)