diff --git a/src/main/java/florizz/core/Parser.java b/src/main/java/florizz/core/Parser.java index 3b40f923c2..f37cea90ef 100644 --- a/src/main/java/florizz/core/Parser.java +++ b/src/main/java/florizz/core/Parser.java @@ -240,7 +240,12 @@ private static AddFlowerCommand handleAddFlower(String argument, boolean enableU String flowerName = argument.substring(0,quantityIndex).trim().toLowerCase(); String quantityString = removePrefix(argument.substring(quantityIndex, prefixIndex), QUANTITY).trim(); // [WARNING] might need to check if it's a valid integer - int quantity = Integer.parseInt(quantityString); + int quantity; + try { + quantity = Integer.parseInt(quantityString); + }catch(NumberFormatException error){ + throw new FlorizzException("Invalid number inputted, please enter a sensible number next time!"); + } String bouquetName = removePrefix(argument.substring(prefixIndex), ADD_FLOWER_PREFIX).trim(); if (includeColour){ int colourIndex = argument.indexOf(COLOUR); @@ -285,7 +290,12 @@ private static RemoveFlowerCommand handleRemoveFlower(String argument) throws Fl String flowerName = argument.substring(0, quantityIndex).trim().toLowerCase(); String quantityString = removePrefix(argument.substring(quantityIndex, prefixIndex), QUANTITY).trim(); // [WARNING] might need to check if it's a valid integer - int quantity = Integer.parseInt(quantityString); + int quantity; + try { + quantity = Integer.parseInt(quantityString); + }catch(NumberFormatException error){ + throw new FlorizzException("Invalid number inputted, please enter a sensible number next time!"); + } String bouquetName = removePrefix(argument.substring(prefixIndex), REMOVE_FLOWER_PREFIX).trim(); if (includeColour){ int colourIndex = argument.indexOf(COLOUR); diff --git a/src/main/java/florizz/objects/Flower.java b/src/main/java/florizz/objects/Flower.java index 6ac2a74f15..1f6e4a6005 100644 --- a/src/main/java/florizz/objects/Flower.java +++ b/src/main/java/florizz/objects/Flower.java @@ -165,9 +165,9 @@ public String getFlowerName() { * @return The name and colour of the flower. */ public String getNameAndColour() { - return colour.toString().charAt(0) + - colour.toString().replaceAll("_", " " ).substring(1).toLowerCase() + " " + - name; + return name + " (" + colour.toString().charAt(0) + + colour.toString().replaceAll("_", " " ).substring(1).toLowerCase() + + ")"; } /** diff --git a/text-ui-test/EXPECTED-UNIX.TXT b/text-ui-test/EXPECTED-UNIX.TXT index 7142416be1..7dad8f5db0 100644 --- a/text-ui-test/EXPECTED-UNIX.TXT +++ b/text-ui-test/EXPECTED-UNIX.TXT @@ -33,92 +33,5 @@ Here is the list of your saved bouquets: No flowers added so far ____________________________________________________________ What can I do for you? ---> Your input is [rose] but I am guessing you mean [Rose] -You have successfully added the following: - - 5 x Rose -> Bouquet: test -Here is the list of your saved bouquets: -1. test : - - 5 x Red Rose - Total estimated price = $10.00 -____________________________________________________________ -What can I do for you? -Here is the list of your saved bouquets: -1. test : - - 5 x Red Rose - Total estimated price = $10.00 -____________________________________________________________ -What can I do for you? ---> Your input is [rose] but I am guessing you mean [Rose] -The flower you're looking for has more than one colour available, each with their own vastly different meanings. Here's some info: -Here is page 1/1 of info regarding flowers whose name contains rose: -1. Name: Rose -Colour: Dark crimson -Occasions: Funeral -Price: $2.00 -Meanings: Mourning -2. Name: Rose -Colour: Red -Occasions: Valentines, Wedding, Mothers day -Price: $2.00 -Meanings: Love -____________________________________________________________ -Type the colour you want to add into the bouquet, or 'cancel' to return to the main menu. -You have successfully added the following: - - 5 x rose -> Bouquet: test -Here is the list of your saved bouquets: -1. test : - - 5 x Red Rose - - 5 x Dark crimson Rose - Total estimated price = $20.00 -____________________________________________________________ -What can I do for you? -Here is the list of your saved bouquets: -1. test : - - 5 x Red Rose - - 5 x Dark crimson Rose - Total estimated price = $20.00 -____________________________________________________________ -What can I do for you? ---> Your input is [rose] but I am guessing you mean [Rose] -You have successfully removed the following: - - 4 x Rose -> Bouquet: test -Here is the list of your saved bouquets: -1. test : - - 1 x Red Rose - - 5 x Dark crimson Rose - Total estimated price = $12.00 -____________________________________________________________ -What can I do for you? ---> Your input is [rose] but I am guessing you mean [Rose] -The flower you're looking for has more than one colour available, each with their own vastly different meanings. Here's some info: -Here is page 1/1 of info regarding flowers whose name contains rose: -1. Name: Rose -Colour: Red -Occasions: Valentines, Wedding, Mothers day -Price: $2.00 -Meanings: Love -2. Name: Rose -Colour: Dark crimson -Occasions: Funeral -Price: $2.00 -Meanings: Mourning -____________________________________________________________ -Type the colour you want to add into the bouquet, or 'cancel' to return to the main menu. -You have successfully removed the following: - - 4 x rose -> Bouquet: test -Here is the list of your saved bouquets: -1. test : - - 1 x Red Rose - - 1 x Dark crimson Rose - Total estimated price = $4.00 -____________________________________________________________ -What can I do for you? -Here is the list of your saved bouquets: -1. test : - - 1 x Red Rose - - 1 x Dark crimson Rose - Total estimated price = $4.00 -____________________________________________________________ -What can I do for you? Enjoy your bouquet! Thank you for using Florizz! ____________________________________________________________ diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 7142416be1..7dad8f5db0 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -33,92 +33,5 @@ Here is the list of your saved bouquets: No flowers added so far ____________________________________________________________ What can I do for you? ---> Your input is [rose] but I am guessing you mean [Rose] -You have successfully added the following: - - 5 x Rose -> Bouquet: test -Here is the list of your saved bouquets: -1. test : - - 5 x Red Rose - Total estimated price = $10.00 -____________________________________________________________ -What can I do for you? -Here is the list of your saved bouquets: -1. test : - - 5 x Red Rose - Total estimated price = $10.00 -____________________________________________________________ -What can I do for you? ---> Your input is [rose] but I am guessing you mean [Rose] -The flower you're looking for has more than one colour available, each with their own vastly different meanings. Here's some info: -Here is page 1/1 of info regarding flowers whose name contains rose: -1. Name: Rose -Colour: Dark crimson -Occasions: Funeral -Price: $2.00 -Meanings: Mourning -2. Name: Rose -Colour: Red -Occasions: Valentines, Wedding, Mothers day -Price: $2.00 -Meanings: Love -____________________________________________________________ -Type the colour you want to add into the bouquet, or 'cancel' to return to the main menu. -You have successfully added the following: - - 5 x rose -> Bouquet: test -Here is the list of your saved bouquets: -1. test : - - 5 x Red Rose - - 5 x Dark crimson Rose - Total estimated price = $20.00 -____________________________________________________________ -What can I do for you? -Here is the list of your saved bouquets: -1. test : - - 5 x Red Rose - - 5 x Dark crimson Rose - Total estimated price = $20.00 -____________________________________________________________ -What can I do for you? ---> Your input is [rose] but I am guessing you mean [Rose] -You have successfully removed the following: - - 4 x Rose -> Bouquet: test -Here is the list of your saved bouquets: -1. test : - - 1 x Red Rose - - 5 x Dark crimson Rose - Total estimated price = $12.00 -____________________________________________________________ -What can I do for you? ---> Your input is [rose] but I am guessing you mean [Rose] -The flower you're looking for has more than one colour available, each with their own vastly different meanings. Here's some info: -Here is page 1/1 of info regarding flowers whose name contains rose: -1. Name: Rose -Colour: Red -Occasions: Valentines, Wedding, Mothers day -Price: $2.00 -Meanings: Love -2. Name: Rose -Colour: Dark crimson -Occasions: Funeral -Price: $2.00 -Meanings: Mourning -____________________________________________________________ -Type the colour you want to add into the bouquet, or 'cancel' to return to the main menu. -You have successfully removed the following: - - 4 x rose -> Bouquet: test -Here is the list of your saved bouquets: -1. test : - - 1 x Red Rose - - 1 x Dark crimson Rose - Total estimated price = $4.00 -____________________________________________________________ -What can I do for you? -Here is the list of your saved bouquets: -1. test : - - 1 x Red Rose - - 1 x Dark crimson Rose - Total estimated price = $4.00 -____________________________________________________________ -What can I do for you? Enjoy your bouquet! Thank you for using Florizz! ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 3b0ff1f652..468ae301eb 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,13 +1,4 @@ help new test mybouquets -add rose /c red /q 5 /to test -mybouquets -add rose /q 5 /to test -dark crimson -mybouquets -remove rose /c red /q 4 /from test -remove rose /q 4 /from test -dark crimson -mybouquets bye \ No newline at end of file