diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index d92e97d08e..8adf0dfc92 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -81,7 +81,7 @@ The generic sequence diagram provides a visual representation of the interaction ActiveEdge application. It illustrates how user commands are parsed, executed, and interact with different modules such as user interface, data storage, and task management. -![Generic Sequence Diagram](https://github.com/AY2324S2-CS2113-W12-2/tp/blob/master/images/GenericSequenceDiagram.png?raw=true) +![Generic Sequence Diagram](https://github.com/AY2324S2-CS2113-W12-2/tp/blob/master/images/GenericSequenceDiagram1.png?raw=true) ### Main Component The `Main` component, residing as a method in the `ActiveEdge` class,serves as the main entry point for the ActiveEdge application, handling user input and diff --git a/src/main/java/command/DeleteLogCommand.java b/src/main/java/command/DeleteLogCommand.java index 902daea9e5..169031b7d5 100644 --- a/src/main/java/command/DeleteLogCommand.java +++ b/src/main/java/command/DeleteLogCommand.java @@ -26,7 +26,7 @@ public DeleteLogCommand(String inputTrimmed) { this.errorRaised = false; if(parts.length == 2){ if(parts[1].contains("i/")){ - indexParts = parts[1].trim().split("i/"); + indexParts = parts[1].trim().split("\\s*i/\\s*");; this.index = Integer.parseInt(indexParts[1].trim()); this.description = indexParts[0].trim().replaceAll("\\s+", " "); if(index <= 0){ @@ -36,7 +36,21 @@ public DeleteLogCommand(String inputTrimmed) { } else { //If no index to be deleted is passed, 1 is considered as the index. this.index = 1; - this.description = parts[1].trim().replaceAll("\\s+", " "); + String[] descriptionParts = parts[1].split("\\s*i/\\s*|\\s+"); + this.description = descriptionParts[0].trim(); + if (descriptionParts.length > 1) { + String[] quantityParts = descriptionParts[1].trim().split("\\s+"); + if (quantityParts.length > 0) { + try { + Integer.parseInt(quantityParts[0]); + String quantityWithoutSpaces = quantityParts[0].trim().replaceAll("\\s+", ""); + this.description += " " + quantityWithoutSpaces; + } catch (NumberFormatException e) { + // If it's not a number, consider it as part of description + this.description += " " + descriptionParts[1].trim(); + } + } + } } } else { CommandUi.printInvalidDeleteFormatMessage(); @@ -53,12 +67,14 @@ public void execute() { int countIndex = 0; for (int i = 0; i < LogList.logList.size(); i++) { Log log = LogList.logList.get(i); - if (log.getDescription().toLowerCase().startsWith("water")) { - if (log instanceof LogWater) { // Check if it's a WaterLog before casting + String logDescription = log.getDescription().toLowerCase().trim(); + if (logDescription.startsWith("water")){ + if (log instanceof LogWater) { + String targetDescription = description.trim().replaceAll("\\s+", ""); LogWater logWater = (LogWater) log; - - if (((logWater.getQuantity()) + "ml").equalsIgnoreCase(description)) { - countIndex = countIndex + 1; + String quantityString = (logWater.getQuantity()) + "ml"; + if (quantityString.equals(targetDescription)) { + countIndex++; if(countIndex == index){ Log deletedLog = LogList.delete(i); CommandUi.printLogDeletedMessage(deletedLog);