-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from Araavinds/b-deleteReceipts
New command to delete receipts
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package executor.command; | ||
|
||
import duke.exception.DukeException; | ||
import interpreter.Parser; | ||
import storage.StorageManager; | ||
|
||
public class CommandReceiptDelete extends Command { | ||
protected String userInput; | ||
|
||
/** | ||
* Constructor for CommandDeleteReceipt subCommand Class. | ||
* @param userInput The user input from the CLI | ||
*/ | ||
public CommandReceiptDelete(String userInput) { | ||
super(); | ||
this.userInput = userInput; | ||
this.description = "Deletes the specific entry that the user wants to remove. \n" | ||
+ "FORMAT: deletereceipt <Index_of_Entry>"; | ||
this.commandType = CommandType.RECEIPTDELETE; | ||
} | ||
|
||
|
||
@Override | ||
public void execute(StorageManager storageManager) { | ||
String outputStr; | ||
String integer = Parser.parseForPrimaryInput(this.commandType, userInput); | ||
try { | ||
int index = Integer.parseInt(integer) - 1; | ||
outputStr = ("Receipt '" | ||
+ (index + 1) | ||
+ ") " | ||
+ "Receipt at index" | ||
+ index | ||
+ " " | ||
+ "'has been deleted. \n"); | ||
storageManager.deleteReceiptByIndex(index); | ||
} catch (DukeException e) { | ||
this.infoCapsule.setCodeError(); | ||
this.infoCapsule.setOutputStr(e.getMessage()); | ||
return; | ||
} | ||
this.infoCapsule.setCodeToast(); | ||
this.infoCapsule.setOutputStr(outputStr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters