forked from nus-cs2113-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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
EugeneChanJiajun
merged 4 commits into
AY2324S2-CS2113-T12-4:master
from
EugeneChanJiajun:master
Mar 17, 2024
Merged
Add parser and exceptions #33
EugeneChanJiajun
merged 4 commits into
AY2324S2-CS2113-T12-4:master
from
EugeneChanJiajun:master
Mar 17, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17acd6e
into
AY2324S2-CS2113-T12-4:master
0 of 6 checks passed
daryltay415
reviewed
Mar 17, 2024
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!"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.