-
Notifications
You must be signed in to change notification settings - Fork 3
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
Change recommendCommand to no longer kick out user if bad input is given #154
Change recommendCommand to no longer kick out user if bad input is given #154
Conversation
/** | ||
* Gets the name the user wants to make for the recommended bouquet and makes sure the name does not already exist | ||
* @param ui Ui to take input and print messages | ||
* @param bouquetList List that contains all bouquets | ||
* @return The chosen valid bouquetName | ||
*/ | ||
public String askBouquetName(Ui ui, ArrayList<Bouquet> bouquetList) { | ||
boolean isValidName = false; | ||
String bouquetName = "placeHolder"; | ||
ui.printAskBouquetName(); | ||
while (!isValidName) { | ||
bouquetName = ui.getInput(); | ||
if (bouquetList.contains(new Bouquet(bouquetName))) { | ||
System.out.println("Sorry a bouquet with this name already exists, please enter another name"); | ||
} else { | ||
isValidName = true; | ||
} | ||
} | ||
return bouquetName; | ||
} | ||
|
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.
This should fix the naming issue, great job 👍
boolean isValidFormat = false; | ||
boolean isValidOccasion = false; | ||
String occasionInput = "placeholder"; | ||
while (!(isValidFormat && isValidOccasion)) { | ||
occasionInput = ui.printAskOccasion(); | ||
isValidFormat = Parser.parseOccasion(occasionInput); | ||
isValidOccasion = Flower.isValidOccasion(occasionInput); | ||
// check if occasion is in our dictionary | ||
if (!isValidOccasion) { | ||
System.out.println("This occasion does not exist."); | ||
} |
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.
Makes code more readable
String saveInput = "placeHolder"; | ||
boolean isValidFormat = false; | ||
boolean isValidInput = false; | ||
while (!(isValidInput && isValidFormat)) { | ||
saveInput = ui.printAskSaveBouquet(recommendedBouquet); | ||
isValidFormat = Parser.parseSaveBouquet(saveInput); | ||
isValidInput = (saveInput.equalsIgnoreCase("yes") || saveInput.equalsIgnoreCase("no")); | ||
} |
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.
isValidInput
might not be necessary since parseSaveBouquet
already used regex, although that one only accepts lower case input. If you didn't change parseSaveBouquet
, the method might still reject capitalised yes even with equalsIgnoreCase
.
throw new FlorizzException("Incorrect format detected! " + | ||
System.out.println("Incorrect format detected! " + | ||
"Please input a single occasion"); | ||
return false; |
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.
It might be good if all system.out
should be done by Ui
only to follow single responsibility principle. I understand why you remove the florizz exception since it kinds of stop users from inputting more command.
[IMPORTANT] I changed the recommend command function to no longer throw execeptions and kick out the user if they sent the wrong input. Please do take a look and request changes if something doesnt look right. As of my brief testing the only time it gets kicked out is if they input a occasion colour combi that does not have any flowers under