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

Mohamed ijaaz recommend #155

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/main/java/florizz/command/RecommendCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ public boolean execute(ArrayList<Bouquet> bouquetList, Ui ui) throws FlorizzExce
* @param bouquetList List that contains all bouquets
* @return The chosen valid bouquetName
*/
public String askBouquetName(Ui ui, ArrayList<Bouquet> bouquetList) {
public String askBouquetName(Ui ui, ArrayList<Bouquet> bouquetList) throws FlorizzException {
boolean isValidName = false;
String bouquetName = "placeHolder";
ui.printAskBouquetName();
while (!isValidName) {
bouquetName = ui.getInput();
Parser.checkRecommendExitCondition(bouquetName);

Choose a reason for hiding this comment

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

Great way of implementing cancelling commands!

if (bouquetList.contains(new Bouquet(bouquetName))) {
System.out.println("Sorry a bouquet with this name already exists, please enter another name");
} else {
Expand Down Expand Up @@ -91,18 +92,21 @@ private void addRandomFlowers(ArrayList<Flower> eligibleFlowers, Bouquet recomme
* Asks user for occasion
* @return Occasion enum
*/
private Flower.Occasion askOccasion(Ui ui) {
private Flower.Occasion askOccasion(Ui ui) throws FlorizzException{
logger.entering(RecommendCommand.class.getName(), "askOccasion");
boolean isValidFormat = false;
boolean isValidOccasion = false;
String occasionInput = "placeholder";
ui.printAskOccasion();
while (!(isValidFormat && isValidOccasion)) {
occasionInput = ui.printAskOccasion();
occasionInput = ui.getInput();
Parser.checkRecommendExitCondition(occasionInput);
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.");
System.out.println("This occasion does not exist." +
"Type 'cancel' if you would like to exit the recommendation page");
}
}

Expand All @@ -116,20 +120,23 @@ private Flower.Occasion askOccasion(Ui ui) {
* @param eligibleFlowers list of flowers to choose from
* @return Colour enum
*/
private Flower.Colour askColour(Ui ui, ArrayList<Flower> eligibleFlowers) {
private Flower.Colour askColour(Ui ui, ArrayList<Flower> eligibleFlowers) throws FlorizzException{
assert !eligibleFlowers.isEmpty() : "Eligible flowers should not be empty";
logger.entering(RecommendCommand.class.getName(), "askColour");
String colourInput = "placeHolder";
boolean isValidFormat = false;
boolean isValidColour = false;
ui.printAskColour(eligibleFlowers);
while (!(isValidColour && isValidFormat)) {
colourInput = ui.printAskColour(eligibleFlowers);
colourInput = ui.getInput();
Parser.checkRecommendExitCondition(colourInput);
isValidFormat = Parser.parseColour(colourInput);
isValidColour = Flower.isValidColour(colourInput);

// check if colour is in our dictionary
if (!isValidColour) {
System.out.println("This colour does not exist.");
System.out.println("This colour does not exist. " +
"Type 'cancel' if you would like to exit the recommendation page");
}
}

Expand All @@ -144,7 +151,7 @@ private void askSaveBouquet(Ui ui, ArrayList<Bouquet> bouquetList,
boolean isValidFormat = false;
boolean isValidInput = false;
while (!(isValidInput && isValidFormat)) {
saveInput = ui.printAskSaveBouquet(recommendedBouquet);
saveInput = ui.printAskSaveBouquet(recommendedBouquet).toLowerCase();
isValidFormat = Parser.parseSaveBouquet(saveInput);
isValidInput = (saveInput.equalsIgnoreCase("yes") || saveInput.equalsIgnoreCase("no"));
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/florizz/command/SaveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public SaveCommand(String bouquetName) {
*/
@Override
public boolean execute(ArrayList<Bouquet> bouquetList, Ui ui) throws FlorizzException {
assert !bouquetName.isEmpty() : "bouquet name cannot be empty";
int bouquetIdx = bouquetList.indexOf(new Bouquet(bouquetName));
if (bouquetIdx == -1) {
throw new FlorizzException("This bouquet does not exist. Create it by typing 'new <BOUQUETNAME>'");
throw new FlorizzException("This bouquet does not exist. Create it by typing 'new <bouquetName>'");
}
Storage storage = new Storage();
try {
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/florizz/core/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static String[] commandHandler(String input) throws FlorizzException {
if (firstWhitespace != -1) {
outputs[0] = FuzzyLogic.detectItem(trimmedInput.substring(0,firstWhitespace).toLowerCase());
switch (outputs[0]) {
case ("save"):
case ("save"): // Fallthrough
case ("delete"): // Fallthrough
case ("new"):
outputs[1] = trimmedInput.substring(firstWhitespace).trim();
Expand Down Expand Up @@ -340,4 +340,15 @@ public static boolean parseSaveBouquet(String argument) {

return true;
}

/**
* Checks if the user has entered the exit word for the recommend page
* @param input Input from the user
* @throws FlorizzException Thrown when the user has entered the exit word
*/
public static void checkRecommendExitCondition(String input) throws FlorizzException{
if (input.equalsIgnoreCase("cancel")) {
throw new FlorizzException("Leaving recommend");
}
}
}
14 changes: 8 additions & 6 deletions src/main/java/florizz/core/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,25 +340,27 @@ public void printIOError() {

/**
* ask user for occasion input
* @return String of occasion input
*/
public String printAskOccasion() {
public void printAskOccasion() {
System.out.println("For what occasion are you buying flowers for?");
this.printAllOccasions();
return inputScanner.nextLine();
System.out.println("Type 'cancel' if you would like to exit the recommendation page");
}

/**
* Prints prompt to ask user to input bouquet name for recommended bouquet
*/
public void printAskBouquetName() {
System.out.println("Great we managed to find some flowers for you!");
System.out.println("Before we carry on what would you like to call your bouquet?");
System.out.println("Note: please take note 'cancel' cannot be used as a bouquet name");

Choose a reason for hiding this comment

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

Good catch!

}

/**
* ask user for colour input
* @param eligibleFlowers list of flowers that are eligible for the occasion
* @return String of colour input
*/
public String printAskColour(ArrayList<Flower> eligibleFlowers) {
public void printAskColour(ArrayList<Flower> eligibleFlowers) {
System.out.println("What colour would you like your bouquets to be?");

// print all available colours in a given array list
Expand All @@ -373,8 +375,8 @@ public String printAskColour(ArrayList<Flower> eligibleFlowers) {
for (String colour : colourList){
System.out.println("- " + colour);
}
System.out.println("Type 'cancel' if you would like to exit the recommendation page");
printBreakLine();
return inputScanner.nextLine();
}

public String printAskSaveBouquet(Bouquet recommendedBouquet) {
Expand Down
Loading