From 48b9968b1bd735576ebd75c6782a8d8fbe4ebba7 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Mon, 11 Nov 2024 19:56:01 +0800 Subject: [PATCH 1/7] Add HELP_MESSAGE --- src/main/java/tutorlink/commons/Commons.java | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/tutorlink/commons/Commons.java b/src/main/java/tutorlink/commons/Commons.java index 7fe562d0a1..2b6852a15f 100644 --- a/src/main/java/tutorlink/commons/Commons.java +++ b/src/main/java/tutorlink/commons/Commons.java @@ -49,4 +49,47 @@ public class Commons { //Exit public static final String EXIT = "Goodbye! See you soon!"; + + //Help + public static final String HELP_MESSAGE = """ + ------------------- List of Commands -------------------- + help: Displays list of commands + Example: help + + add_student: Adds a student to the class roster + Example: add_student i/A1234567X n/John Doe + + delete_student: Deletes a student from the class roster + Example: delete_student i/A1234567X + + list_student: Lists all students in the class + Example: list_student + + find_student: Finds a student in the class roster by name or matric number + Example: find_student i/A1234567X n/John Doe + + add_component: Adds a new grading component to the class + Example: add_component c/Quiz 1 w/30 m/50 + + delete_component: Deletes a grading component from the class + Example: delete_component c/Quiz 1 + + update_component: Updates a component with a new maxscore or weight + Example: update_component c/Quiz 1 w/40 m/60 + + list_component: Lists all grading components + Example: list_component + + add_grade: Adds a grade for a student for a specific component + Example: add_grade i/A1234567X c/Quiz 1 s/45 + + delete_grade: Deletes a student's grade for a specific component + Example: delete_grade i/A1234567X c/Quiz 1 + + list_grade: Lists all grades for a student + Example: list_grade i/A1234567X + + bye: Exits the program + Example: bye + -------------------------------------------------------------"""; } From cabc39e45bbfd304f7028fdff7d226ad4b2e9a76 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Mon, 11 Nov 2024 19:56:22 +0800 Subject: [PATCH 2/7] Add helpcommand into Parser --- src/main/java/tutorlink/parser/Parser.java | 59 ++++++++++++---------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/main/java/tutorlink/parser/Parser.java b/src/main/java/tutorlink/parser/Parser.java index 6d4fa2cccd..016583097e 100644 --- a/src/main/java/tutorlink/parser/Parser.java +++ b/src/main/java/tutorlink/parser/Parser.java @@ -14,7 +14,9 @@ import tutorlink.command.AddGradeCommand; import tutorlink.command.AddComponentCommand; import tutorlink.command.UpdateComponentCommand; +import tutorlink.command.HelpCommand; import tutorlink.exceptions.IllegalValueException; + import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -55,44 +57,47 @@ public Command getCommand(String line) { String commandWord = extractCommandWord(line); switch (commandWord.toLowerCase()) { - case AddStudentCommand.COMMAND_WORD: - return new AddStudentCommand(); + case AddStudentCommand.COMMAND_WORD: + return new AddStudentCommand(); + + case DeleteStudentCommand.COMMAND_WORD: + return new DeleteStudentCommand(); - case DeleteStudentCommand.COMMAND_WORD: - return new DeleteStudentCommand(); + case FindStudentCommand.COMMAND_WORD: + return new FindStudentCommand(); - case FindStudentCommand.COMMAND_WORD: - return new FindStudentCommand(); + case ListStudentCommand.COMMAND_WORD: + return new ListStudentCommand(); - case ListStudentCommand.COMMAND_WORD: - return new ListStudentCommand(); + case AddGradeCommand.COMMAND_WORD: + return new AddGradeCommand(); - case AddGradeCommand.COMMAND_WORD: - return new AddGradeCommand(); + case DeleteGradeCommand.COMMAND_WORD: + return new DeleteGradeCommand(); - case DeleteGradeCommand.COMMAND_WORD: - return new DeleteGradeCommand(); + case AddComponentCommand.COMMAND_WORD: + return new AddComponentCommand(); - case AddComponentCommand.COMMAND_WORD: - return new AddComponentCommand(); + case DeleteComponentCommand.COMMAND_WORD: + return new DeleteComponentCommand(); - case DeleteComponentCommand.COMMAND_WORD: - return new DeleteComponentCommand(); + case ListComponentCommand.COMMAND_WORD: + return new ListComponentCommand(); - case ListComponentCommand.COMMAND_WORD: - return new ListComponentCommand(); + case ListGradeCommand.COMMAND_WORD: + return new ListGradeCommand(); - case ListGradeCommand.COMMAND_WORD: - return new ListGradeCommand(); + case UpdateComponentCommand.COMMAND_WORD: + return new UpdateComponentCommand(); - case UpdateComponentCommand.COMMAND_WORD: - return new UpdateComponentCommand(); + case ExitCommand.COMMAND_WORD: + return new ExitCommand(); - case ExitCommand.COMMAND_WORD: - return new ExitCommand(); + case HelpCommand.COMMAND_WORD: + return new HelpCommand(); - default: - return new InvalidCommand(); + default: + return new InvalidCommand(); } } @@ -102,7 +107,7 @@ public Command getCommand(String line) { * and are extracted into a map where each prefix is a key and the corresponding argument is the value. * * @param argumentPrefixes An array of valid argument prefixes (e.g., "n/", "i/"). - * @param line The user input containing command arguments. + * @param line The user input containing command arguments. * @return A {@code HashMap} where keys are prefixes (e.g., "n/", "i/") and values are the corresponding arguments. */ public HashMap getArguments(String[] argumentPrefixes, String line) throws IllegalValueException { From dd2ec332db6853aa00f78c45c0d8138cee0f2c8b Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Mon, 11 Nov 2024 19:56:35 +0800 Subject: [PATCH 3/7] Create HelpCommand --- .../java/tutorlink/command/HelpCommand.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/tutorlink/command/HelpCommand.java diff --git a/src/main/java/tutorlink/command/HelpCommand.java b/src/main/java/tutorlink/command/HelpCommand.java new file mode 100644 index 0000000000..90be9a8b52 --- /dev/null +++ b/src/main/java/tutorlink/command/HelpCommand.java @@ -0,0 +1,52 @@ +package tutorlink.command; + +import tutorlink.appstate.AppState; +import tutorlink.commons.Commons; +import tutorlink.exceptions.TutorLinkException; +import tutorlink.result.CommandResult; + +import java.util.HashMap; + +/** + * Represents a help command that displays usage information. + * This command shows a list of all available commands and their proper usage. + * This command is triggered using the "help" keyword. + */ +public class HelpCommand extends Command { + /** + * Command word that triggers this command + */ + public static final String COMMAND_WORD = "help"; + + /** + * Creates a new HelpCommand instance. + */ + public HelpCommand() { + } + + /** + * Executes the help command. + * Returns a command result containing the help message that lists + * all available commands and their usage. + * + * @param state The current state of the application + * @param arguments Command arguments (not used for help command) + * @return CommandResult containing the help message + * @throws TutorLinkException if there's an error executing the command + */ + @Override + public CommandResult execute(AppState state, HashMap arguments) throws TutorLinkException { + return new CommandResult(Commons.HELP_MESSAGE); + } + + /** + * Gets the argument prefixes that this command accepts. + * Help command doesn't accept any arguments. + * + * @return null since this command takes no arguments + */ + @Override + public String[] getArgumentPrefixes() { + return null; + } +} \ No newline at end of file From 6cc187e2660cf437d0141d972c174cca3a7ac3fe Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Mon, 11 Nov 2024 20:10:00 +0800 Subject: [PATCH 4/7] Fix checkStyle --- src/main/java/tutorlink/parser/Parser.java | 54 +++++++++++----------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/tutorlink/parser/Parser.java b/src/main/java/tutorlink/parser/Parser.java index 016583097e..7cc560ec95 100644 --- a/src/main/java/tutorlink/parser/Parser.java +++ b/src/main/java/tutorlink/parser/Parser.java @@ -57,47 +57,47 @@ public Command getCommand(String line) { String commandWord = extractCommandWord(line); switch (commandWord.toLowerCase()) { - case AddStudentCommand.COMMAND_WORD: - return new AddStudentCommand(); + case AddStudentCommand.COMMAND_WORD: + return new AddStudentCommand(); - case DeleteStudentCommand.COMMAND_WORD: - return new DeleteStudentCommand(); + case DeleteStudentCommand.COMMAND_WORD: + return new DeleteStudentCommand(); - case FindStudentCommand.COMMAND_WORD: - return new FindStudentCommand(); + case FindStudentCommand.COMMAND_WORD: + return new FindStudentCommand(); - case ListStudentCommand.COMMAND_WORD: - return new ListStudentCommand(); + case ListStudentCommand.COMMAND_WORD: + return new ListStudentCommand(); - case AddGradeCommand.COMMAND_WORD: + case AddGradeCommand.COMMAND_WORD: return new AddGradeCommand(); - case DeleteGradeCommand.COMMAND_WORD: - return new DeleteGradeCommand(); + case DeleteGradeCommand.COMMAND_WORD: + return new DeleteGradeCommand(); - case AddComponentCommand.COMMAND_WORD: - return new AddComponentCommand(); + case AddComponentCommand.COMMAND_WORD: + return new AddComponentCommand(); - case DeleteComponentCommand.COMMAND_WORD: - return new DeleteComponentCommand(); + case DeleteComponentCommand.COMMAND_WORD: + return new DeleteComponentCommand(); - case ListComponentCommand.COMMAND_WORD: - return new ListComponentCommand(); + case ListComponentCommand.COMMAND_WORD: + return new ListComponentCommand(); - case ListGradeCommand.COMMAND_WORD: - return new ListGradeCommand(); + case ListGradeCommand.COMMAND_WORD: + return new ListGradeCommand(); - case UpdateComponentCommand.COMMAND_WORD: - return new UpdateComponentCommand(); + case UpdateComponentCommand.COMMAND_WORD: + return new UpdateComponentCommand(); - case ExitCommand.COMMAND_WORD: - return new ExitCommand(); + case ExitCommand.COMMAND_WORD: + return new ExitCommand(); - case HelpCommand.COMMAND_WORD: - return new HelpCommand(); + case HelpCommand.COMMAND_WORD: + return new HelpCommand(); - default: - return new InvalidCommand(); + default: + return new InvalidCommand(); } } From 455f63f8d7da1af1933b007066d192a237f4d1f7 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Mon, 11 Nov 2024 20:14:38 +0800 Subject: [PATCH 5/7] Fix checkStyle second time --- src/main/java/tutorlink/parser/Parser.java | 56 +++++++++++----------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/tutorlink/parser/Parser.java b/src/main/java/tutorlink/parser/Parser.java index 7cc560ec95..1eb1d3e665 100644 --- a/src/main/java/tutorlink/parser/Parser.java +++ b/src/main/java/tutorlink/parser/Parser.java @@ -57,47 +57,47 @@ public Command getCommand(String line) { String commandWord = extractCommandWord(line); switch (commandWord.toLowerCase()) { - case AddStudentCommand.COMMAND_WORD: - return new AddStudentCommand(); + case AddStudentCommand.COMMAND_WORD: + return new AddStudentCommand(); - case DeleteStudentCommand.COMMAND_WORD: - return new DeleteStudentCommand(); + case DeleteStudentCommand.COMMAND_WORD: + return new DeleteStudentCommand(); - case FindStudentCommand.COMMAND_WORD: - return new FindStudentCommand(); + case FindStudentCommand.COMMAND_WORD: + return new FindStudentCommand(); - case ListStudentCommand.COMMAND_WORD: - return new ListStudentCommand(); + case ListStudentCommand.COMMAND_WORD: + return new ListStudentCommand(); - case AddGradeCommand.COMMAND_WORD: - return new AddGradeCommand(); + case AddGradeCommand.COMMAND_WORD: + return new AddGradeCommand(); - case DeleteGradeCommand.COMMAND_WORD: - return new DeleteGradeCommand(); + case DeleteGradeCommand.COMMAND_WORD: + return new DeleteGradeCommand(); - case AddComponentCommand.COMMAND_WORD: - return new AddComponentCommand(); + case AddComponentCommand.COMMAND_WORD: + return new AddComponentCommand(); - case DeleteComponentCommand.COMMAND_WORD: - return new DeleteComponentCommand(); + case DeleteComponentCommand.COMMAND_WORD: + return new DeleteComponentCommand(); - case ListComponentCommand.COMMAND_WORD: - return new ListComponentCommand(); + case ListComponentCommand.COMMAND_WORD: + return new ListComponentCommand(); - case ListGradeCommand.COMMAND_WORD: - return new ListGradeCommand(); + case ListGradeCommand.COMMAND_WORD: + return new ListGradeCommand(); - case UpdateComponentCommand.COMMAND_WORD: - return new UpdateComponentCommand(); + case UpdateComponentCommand.COMMAND_WORD: + return new UpdateComponentCommand(); - case ExitCommand.COMMAND_WORD: - return new ExitCommand(); + case ExitCommand.COMMAND_WORD: + return new ExitCommand(); - case HelpCommand.COMMAND_WORD: - return new HelpCommand(); + case HelpCommand.COMMAND_WORD: + return new HelpCommand(); - default: - return new InvalidCommand(); + default: + return new InvalidCommand(); } } From f17e374f0631376b3bac4a106438f7e57816767a Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Mon, 11 Nov 2024 20:16:30 +0800 Subject: [PATCH 6/7] Add newline at the end --- src/main/java/tutorlink/command/HelpCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/tutorlink/command/HelpCommand.java b/src/main/java/tutorlink/command/HelpCommand.java index 90be9a8b52..66b809a744 100644 --- a/src/main/java/tutorlink/command/HelpCommand.java +++ b/src/main/java/tutorlink/command/HelpCommand.java @@ -49,4 +49,4 @@ public CommandResult execute(AppState state, HashMap arguments) public String[] getArgumentPrefixes() { return null; } -} \ No newline at end of file +} From ecf07302cdd7bf1a70254def4d2a4b43de265979 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Mon, 11 Nov 2024 20:27:36 +0800 Subject: [PATCH 7/7] Remove redundant break lines --- src/main/java/tutorlink/commons/Commons.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/tutorlink/commons/Commons.java b/src/main/java/tutorlink/commons/Commons.java index 2b6852a15f..e3f27e16df 100644 --- a/src/main/java/tutorlink/commons/Commons.java +++ b/src/main/java/tutorlink/commons/Commons.java @@ -52,7 +52,6 @@ public class Commons { //Help public static final String HELP_MESSAGE = """ - ------------------- List of Commands -------------------- help: Displays list of commands Example: help @@ -91,5 +90,5 @@ public class Commons { bye: Exits the program Example: bye - -------------------------------------------------------------"""; + """; }