diff --git a/build.gradle b/build.gradle index 25409b5f67..164797871a 100644 --- a/build.gradle +++ b/build.gradle @@ -43,4 +43,5 @@ checkstyle { run{ standardInput = System.in + enableAssertions = false; } diff --git a/src/main/java/florizz/command/FlowerCommand.java b/src/main/java/florizz/command/FlowerCommand.java index 1424869f6f..decd803a67 100644 --- a/src/main/java/florizz/command/FlowerCommand.java +++ b/src/main/java/florizz/command/FlowerCommand.java @@ -1,6 +1,7 @@ package florizz.command; import florizz.core.FlorizzException; +import florizz.core.OccasionDictionary; import florizz.core.Ui; import florizz.objects.Bouquet; @@ -17,6 +18,8 @@ public FlowerCommand(String occasion) { public boolean execute(ArrayList bouquetList, Ui ui) throws FlorizzException { if (occasion.isBlank()) { ui.printAllDictFlowerName(); + } else if (!OccasionDictionary.contains(occasion)){ + throw new FlorizzException("This occasion does not exist type 'occasion' to get a list of occasions"); } else { ui.printOccasionFlower(occasion); } diff --git a/src/main/java/florizz/core/OccasionDictionary.java b/src/main/java/florizz/core/OccasionDictionary.java index 9e6323e147..3b6c30e2d5 100644 --- a/src/main/java/florizz/core/OccasionDictionary.java +++ b/src/main/java/florizz/core/OccasionDictionary.java @@ -12,7 +12,7 @@ public static void add(String Occasion) { public static void startup() { for (int i = 0; i < FlowerDictionary.size(); i++) { - add(FlowerDictionary.get(i).getOccasion()); + add(FlowerDictionary.get(i).getOccasion().toLowerCase()); } } @@ -25,4 +25,8 @@ public static void print() { System.out.println(occasion); } } + + public static boolean contains(String occasion) { + return uniqueOccasions.contains(occasion.toLowerCase()); + } } diff --git a/src/main/java/florizz/core/Parser.java b/src/main/java/florizz/core/Parser.java index 7dd2bba6c2..d7c095510a 100644 --- a/src/main/java/florizz/core/Parser.java +++ b/src/main/java/florizz/core/Parser.java @@ -44,6 +44,7 @@ private static FlowerCommand handleFlowerCommand(String input) { private static InfoCommand handleInfoCommand(String input) { String flowerName = input.substring(input.indexOf(" ") + 1); + assert !flowerName.isEmpty() : "This string is empty"; return new InfoCommand(flowerName); } diff --git a/src/main/java/florizz/core/Ui.java b/src/main/java/florizz/core/Ui.java index ba64ba23fa..45b0348c45 100644 --- a/src/main/java/florizz/core/Ui.java +++ b/src/main/java/florizz/core/Ui.java @@ -58,11 +58,10 @@ public void printHelpMessage() { System.out.println("1. new - Add a bouquet"); System.out.println("2. delete - Delete a bouquets"); System.out.println("3. mybouquets - List current saved bouquets"); - System.out.println("4. flower - List all flowers in Florizz or all flowers for an occasion"); - System.out.println("5. info - Provide information on chosen flower"); - System.out.println("6. flower - Shows a list of flowers that can be added into mybouquets"); - System.out.println("7. flower - Shows a list of flowers associated with said occasion"); - System.out.println("8. bye - Exits the programme"); + System.out.println("4. info - Provide information on chosen flower"); + System.out.println("5. flower - Shows a list of flowers that can be added into mybouquets"); + System.out.println("6. flower - Shows a list of flowers associated with said occasion"); + System.out.println("7. bye - Exits the programme"); printBreakLine(); }