Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parser and exceptions #33

Merged

Conversation

EugeneChanJiajun
Copy link

No description provided.

@EugeneChanJiajun EugeneChanJiajun merged commit 17acd6e into AY2324S2-CS2113-T12-4:master Mar 17, 2024
0 of 6 checks passed
@EugeneChanJiajun EugeneChanJiajun linked an issue Mar 17, 2024 that may be closed by this pull request
@EugeneChanJiajun EugeneChanJiajun self-assigned this Mar 17, 2024
@EugeneChanJiajun EugeneChanJiajun added type.Task Something that needs to be done, but not a story, bug, or an epic. e.g. Move testing code into a new priority.High Must do labels Mar 17, 2024
@EugeneChanJiajun EugeneChanJiajun added this to the v1.0 milestone Mar 17, 2024
@daryltay415 daryltay415 self-requested a review March 17, 2024 15:11
Comment on lines +1 to +37
package seedu.duke;

public class Parser {
public static void getList(TravelActivityList list){
System.out.println("Here are the travel activities in your list:");
list.listTravelActivities();
}

public static void addCommand(String line, String[] command, TravelActivityList list) throws OmniException{
if (command.length >= 2) {
TravelActivity newActivity = new TravelActivity(line.substring(4));
list.addTravelActivity(newActivity);
System.out.println("I added a new travel activity");
System.out.println(newActivity);
} else {
throw new OmniException("The description of add cannot be empty!");
}
}

public static void deleteCommand(String[] command, TravelActivityList list) throws OmniException {
if (command.length == 2){
int listNumber = Integer.parseInt(command[1]);
list.removeTravelActivity(listNumber);
} else {
throw new OmniException("Please specify which task to delete");
}
}

public static void findCommand(String[] command, TravelActivityList list) throws OmniException{
if (command.length == 2) {
String keyword = command[1];
list.searchKeyword(keyword);
} else {
throw new OmniException("Please specify which keyword you want to find!");
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +16 to +60
String[] command = line.split(" ");

switch (command[0].toLowerCase()) {
case "list":
Ui.printLine();
Parser.getList(list);
Ui.printLine();
break;
case "add":
try {
Ui.printLine();
Parser.addCommand(line, command, list);
Ui.printLine();
}
catch (OmniException exception){
Ui.printLine();
System.out.println("Warning! " + exception.getMessage());
}
break;
case "delete":
try {
Ui.printLine();
Parser.deleteCommand(command, list);
Ui.printLine();
}
catch (OmniException exception){
Ui.printLine();
System.out.println("Warning! " + exception.getMessage());
}
break;
case "find":
try {
Ui.printLine();
Parser.findCommand(command, list);
Ui.printLine();
}
catch (OmniException exception){
Ui.printLine();
System.out.println("Warning! " + exception.getMessage());
}
break;
case "bye":
Ui.printLine();
System.out.println("Hope to see you again soon. Bye!");
Ui.printLine();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catching of exceptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority.High Must do type.Task Something that needs to be done, but not a story, bug, or an epic. e.g. Move testing code into a new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement parser support for help menu
2 participants