Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2324S2#41 from Ijaaz01/MohamedIjaaz-b…
Browse files Browse the repository at this point in the history
…ugFixes

Fix bug for add and remove flower command
  • Loading branch information
IanFH authored Mar 20, 2024
2 parents cd9bf8c + d2a5fd0 commit 2429b11
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/main/java/florizz/command/AddFlowerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ public boolean execute(ArrayList<Bouquet> bouquetList, Ui ui) throws FlorizzExce
}

boolean doesFlowerExist = false;
FlowerDictionary flowerDictionary = new FlowerDictionary();
Flower flowerToBeAdded = new Flower();
for (int i = 0; !doesFlowerExist && i < flowerDictionary.size(); i++) {
if (flowerDictionary.get(i).getFlowerName().equals(flowerName)) {
flowerToBeAdded = flowerDictionary.get(i);
for (int i = 0; !doesFlowerExist && i < FlowerDictionary.size(); i++) {
if (FlowerDictionary.get(i).getFlowerName().toLowerCase().equals(flowerName)) {
flowerToBeAdded = FlowerDictionary.get(i);
doesFlowerExist = true;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/florizz/command/RemoveFlowerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ public boolean execute(ArrayList<Bouquet> bouquetList, Ui ui) throws FlorizzExce
}

boolean doesFlowerExist = false;
FlowerDictionary flowerDictionary = new FlowerDictionary();
Flower flowerToBeAdded = new Flower();
for (int i = 0; !doesFlowerExist && i < flowerDictionary.size(); i++) {
if (flowerDictionary.get(i).getFlowerName().equals(flowerName)) {
flowerToBeAdded = flowerDictionary.get(i);
for (int i = 0; !doesFlowerExist && i < FlowerDictionary.size(); i++) {
if (FlowerDictionary.get(i).getFlowerName().toLowerCase().equals(flowerName)) {
flowerToBeAdded = FlowerDictionary.get(i);
doesFlowerExist = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/florizz/core/FlowerDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class FlowerDictionary {
* @param colour Colour of flower to be added
* @param occasion Occasion that the flower is bought for
*/
public static void add(String name, String colour, String occasion) {
private static void add(String name, String colour, String occasion) {
flowerDict.add(new Flower(name, colour, occasion));
}

Expand All @@ -31,7 +31,7 @@ public static void startup() {
add("Babys Breath", "White", "Wedding");
add("Chrysanthemum", "White", "Funeral");
add("Hydrangea", "Blue", "Wedding");
add("Carnation", "Pink", "Mother's Day");
add("Carnation", "Pink", "Mothers Day");
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/florizz/core/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static AddFlowerCommand handleAddFlower(String argument) throws FlorizzE
int prefixIndex = argument.indexOf(ADD_FLOWER_PREFIX);
int quantityIndex = argument.indexOf(QUANTITY);

String flowerName = argument.substring(0,quantityIndex).trim();
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
Integer quantity = Integer.parseInt(quantityString);
Expand All @@ -134,14 +134,15 @@ private static RemoveFlowerCommand handleRemoveFlower(String argument) throws Fl
int prefixIndex = argument.indexOf(REMOVE_FLOWER_PREFIX);
int quantityIndex = argument.indexOf(QUANTITY);

String flowerName = argument.substring(0, quantityIndex).trim();
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
Integer quantity = Integer.parseInt(quantityString);
String bouquetName = removePrefix(argument.substring(prefixIndex), REMOVE_FLOWER_PREFIX).trim();

return new RemoveFlowerCommand(flowerName, quantity, bouquetName);
}

private static InfoCommand handleInfoCommand(String input) {
String flowerName = input.substring(input.indexOf(" ") + 1);
assert !flowerName.isEmpty() : "This string is empty";
Expand Down

0 comments on commit 2429b11

Please sign in to comment.