From bcb2f6d471fb2771ad9fdc6053e6e88462d845ea Mon Sep 17 00:00:00 2001 From: LowTL Date: Mon, 18 Mar 2024 19:38:16 +0800 Subject: [PATCH 1/7] Add exceptions package --- .../java/exception/StockMasterException.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/exception/StockMasterException.java diff --git a/src/main/java/exception/StockMasterException.java b/src/main/java/exception/StockMasterException.java new file mode 100644 index 0000000000..2411a374fd --- /dev/null +++ b/src/main/java/exception/StockMasterException.java @@ -0,0 +1,31 @@ +package exception; +public class StockMasterException extends Exception { + protected String description; + protected String type; + + public StockMasterException(String description, String type) { + this.description = description; + this.type = type; + } + + public StockMasterException() { + this.description = null; + this.type = null; + } + + public void printException() { + switch (this.type) { + case "EMPTY": + if (description.equals("description")) { + System.out.println("The item name cannot be left blank."); + } + break; + case "OUT_OF_BOUNDS": + System.out.println("The index you're accessing is out of bounds."); + break; + default: + System.out.println("Unrecognised error."); + break; + } + } +} From 65997b872c1abb4ed1849db6fdb644d98e3bad5a Mon Sep 17 00:00:00 2001 From: LowTL Date: Mon, 18 Mar 2024 23:40:48 +0800 Subject: [PATCH 2/7] Update UserGuide --- docs/UserGuide.md | 82 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 13 deletions(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index abd9fbe891..d9cbd084b8 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -2,41 +2,97 @@ ## Introduction -{Give a product intro} +StockMaster is a platform aimed at helping SMEs track and organise their inventory. ## Quick Start {Give steps to get started quickly} 1. Ensure that you have Java 11 or above installed. -1. Down the latest version of `Duke` from [here](http://link.to/duke). +2. Download the latest version of `StockMaster` from [here](http://link.to/duke). +3. ## Features {Give detailed description of each feature} -### Adding a todo: `todo` -Adds a new item to the list of todo items. +### Adding an item: `add` +Adds a new item to the list of items. -Format: `todo n/TODO_NAME d/DEADLINE` +Format: `add ITEM_NAME qty/ITEM_QUANTITY [cat/CATEGORY]` -* The `DEADLINE` can be in a natural language format. -* The `TODO_NAME` cannot contain punctuation. +* `CATEGORY` is an optional field. If blank, it will default to `N/A`. Example of usage: +``` +add Apples qty/50 +add Phone qty/5 cat/Electronics +``` -`todo n/Write the rest of the User Guide d/next week` +### Deleting an item: `del` +Deletes the item from the list of items. -`todo n/Refactor the User Guide to remove passive voice d/13/04/2020` +Format: `del ITEM_NAME` + +Example of usage: +``` +del Apples +``` + +### Editing an item: `edit` +Edits the quantity of the item. + +Format: `edit ITEM_NAME qty/NEW_QUANTITY` + +Example of usage: +``` +edit Apples qty/10 +edit Phone qty/0 +``` + +### Listing all items: `list` +Lists all stored items. + +Format: `list [cat/CATEGORY]` + +* `CATEGORY` is an optional field. By default, it will list all the stored items. + +Example of usage: +``` +list +list Electronics +``` + +### List all available commands: `help` +Lists all commands as per the command summary below. + +Format: `help [c/COMMAND]` + +* `COMMAND` is optional. Specifying the command will give a more comprehensive + description of the command. + +Example of usage: +``` +help +help c/add +``` + + +### Closing the app: `exit` +Saves and closes the app safely. + +Format: `exit` ## FAQ **Q**: How do I transfer my data to another computer? -**A**: {your answer here} +**A**: Simply copy and paste the saved folder that is created upon launch of +the application. ## Command Summary -{Give a 'cheat sheet' of commands here} - -* Add todo `todo n/TODO_NAME d/DEADLINE` +* Add new item: `add Apples qty/10 cat/Food` +* Delete an item: `delete Apples` +* List all items: `list` +* List all commands: `help` \ No newline at end of file From b86a0ac4705bf21a9d23a41504f1c1e087f787f6 Mon Sep 17 00:00:00 2001 From: LowTL Date: Wed, 20 Mar 2024 21:44:05 +0800 Subject: [PATCH 3/7] Add general classes --- .../java/calculation/profitCalculator.java | 4 +++ .../java/calculation/quantityCalculator.java | 35 +++++++++++++++++++ src/main/java/constants/UOM.java | 9 +++++ src/main/java/constants/uomList.java | 4 +++ src/main/java/item/Item.java | 22 +++++++++--- 5 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 src/main/java/calculation/profitCalculator.java create mode 100644 src/main/java/calculation/quantityCalculator.java create mode 100644 src/main/java/constants/UOM.java create mode 100644 src/main/java/constants/uomList.java diff --git a/src/main/java/calculation/profitCalculator.java b/src/main/java/calculation/profitCalculator.java new file mode 100644 index 0000000000..96c8a307db --- /dev/null +++ b/src/main/java/calculation/profitCalculator.java @@ -0,0 +1,4 @@ +package calculation; + +public class profitCalculator { +} diff --git a/src/main/java/calculation/quantityCalculator.java b/src/main/java/calculation/quantityCalculator.java new file mode 100644 index 0000000000..46cf5f7b41 --- /dev/null +++ b/src/main/java/calculation/quantityCalculator.java @@ -0,0 +1,35 @@ +package calculation; + +import constants.UOM; +import constants.uomList; +import item.Item; +public class quantityCalculator { + + public int convertUOM(UOM uom) { + int value = 0; + switch (uom) { + case EA: + //fallthrough + case PIECE: + value = 1; + break; + case BOX: + value = 6; + break; + case DOZEN: + value = 12; + break; + case CTN: + value = 24; + break; + default: + break; + } + + return value; + } + + public void updateQty(Item item) { + item.setQuantity(item.getQuantity() + convertUOM(item.getUom())); + } +} diff --git a/src/main/java/constants/UOM.java b/src/main/java/constants/UOM.java new file mode 100644 index 0000000000..7482ac6def --- /dev/null +++ b/src/main/java/constants/UOM.java @@ -0,0 +1,9 @@ +package constants; + +public enum UOM { + PIECE, + EA, + DOZEN, + CTN, + BOX +} diff --git a/src/main/java/constants/uomList.java b/src/main/java/constants/uomList.java new file mode 100644 index 0000000000..8f7b74814f --- /dev/null +++ b/src/main/java/constants/uomList.java @@ -0,0 +1,4 @@ +package constants; + +public class uomList { +} diff --git a/src/main/java/item/Item.java b/src/main/java/item/Item.java index ee17366a0d..d72e58321f 100644 --- a/src/main/java/item/Item.java +++ b/src/main/java/item/Item.java @@ -1,15 +1,21 @@ package item; +import constants.UOM; public class Item { public static int numberOfItems; - private final String itemName; - private int quantity; - private String UOM; + protected final String itemName; + protected int quantity; + protected UOM uom; + protected int uomQty; + protected float costPrice; + protected float salePrice; - public Item(String name, int quantity, String uom) { + + public Item(String name, int quantity, UOM uom, int uomQty) { this.itemName = name; this.quantity = quantity; - this.UOM = uom; + this.uom = uom; + this.uomQty = uomQty; numberOfItems++; } @@ -24,4 +30,10 @@ public int getQuantity() { public void setQuantity(int newQuantity) { this.quantity = newQuantity; } + public UOM getUom() { + return this.uom; + } + public void setUomQty(int newQty) { + this.uomQty = newQty; + } } From 97fe372a0d8cf903269ac49e1254d5002d509ca0 Mon Sep 17 00:00:00 2001 From: LowTL Date: Mon, 25 Mar 2024 22:09:25 +0800 Subject: [PATCH 4/7] Change exception handling --- .../java/calculation/profitCalculator.java | 4 --- .../java/calculation/quantityCalculator.java | 35 ------------------- src/main/java/command/Command.java | 6 ++-- src/main/java/command/DeleteCommand.java | 5 ++- src/main/java/seedu/duke/Duke.java | 7 ++-- 5 files changed, 12 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/calculation/profitCalculator.java delete mode 100644 src/main/java/calculation/quantityCalculator.java diff --git a/src/main/java/calculation/profitCalculator.java b/src/main/java/calculation/profitCalculator.java deleted file mode 100644 index 96c8a307db..0000000000 --- a/src/main/java/calculation/profitCalculator.java +++ /dev/null @@ -1,4 +0,0 @@ -package calculation; - -public class profitCalculator { -} diff --git a/src/main/java/calculation/quantityCalculator.java b/src/main/java/calculation/quantityCalculator.java deleted file mode 100644 index 46cf5f7b41..0000000000 --- a/src/main/java/calculation/quantityCalculator.java +++ /dev/null @@ -1,35 +0,0 @@ -package calculation; - -import constants.UOM; -import constants.uomList; -import item.Item; -public class quantityCalculator { - - public int convertUOM(UOM uom) { - int value = 0; - switch (uom) { - case EA: - //fallthrough - case PIECE: - value = 1; - break; - case BOX: - value = 6; - break; - case DOZEN: - value = 12; - break; - case CTN: - value = 24; - break; - default: - break; - } - - return value; - } - - public void updateQty(Item item) { - item.setQuantity(item.getQuantity() + convertUOM(item.getUom())); - } -} diff --git a/src/main/java/command/Command.java b/src/main/java/command/Command.java index 41649ed097..a71e7f8779 100644 --- a/src/main/java/command/Command.java +++ b/src/main/java/command/Command.java @@ -1,6 +1,8 @@ package command; -public abstract class Command { +import exceptions.CommandFormatException; - public abstract void execute(); +public abstract class Command { + + public abstract void execute() throws CommandFormatException; } diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java index 2da1c3483d..7ce9312919 100644 --- a/src/main/java/command/DeleteCommand.java +++ b/src/main/java/command/DeleteCommand.java @@ -1,7 +1,9 @@ package command; +import exceptions.CommandFormatException; import item.Item; import itemlist.Itemlist; +import parser.CommandType; import storage.Storage; public class DeleteCommand extends Command { @@ -12,7 +14,7 @@ public DeleteCommand(String itemName) { this.itemName = itemName; } - public void execute() { + public void execute() throws CommandFormatException { int index = -1; for (Item item : Itemlist.getItems()) { if (item.getItemName().toLowerCase().equals(itemName)) { @@ -22,6 +24,7 @@ public void execute() { } if (index == -1) { //throw exception; + throw new CommandFormatException(CommandType.DEL); } else { Itemlist.deleteItem(index); } diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 9af6f9d0f9..8d14fe25b9 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -2,6 +2,7 @@ import command.Command; import command.ExitCommand; +import exceptions.CommandFormatException; import parser.Parser; import ui.TextUi; @@ -17,17 +18,17 @@ public class Duke { /** * Main entry-point for the java.duke.Duke application. */ - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException, CommandFormatException { new Duke().run(); } - public void run() throws IOException { + public void run() throws IOException, CommandFormatException { ui.showWelcomeMessage("1.0", "./StockMasterData.txt"); this.normalOperation(); ui.showGoodByeMessage("./StockMasterData.txt"); } - private void normalOperation() throws IOException { + private void normalOperation() throws IOException, CommandFormatException { String userInput; do { userInput = ui.getUserInput(); From d86d422ded91c00deb3949def1a6b5d5d08848f0 Mon Sep 17 00:00:00 2001 From: LowTL Date: Mon, 25 Mar 2024 22:10:28 +0800 Subject: [PATCH 5/7] Remove duplicate exceptions folder --- .../java/exception/StockMasterException.java | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 src/main/java/exception/StockMasterException.java diff --git a/src/main/java/exception/StockMasterException.java b/src/main/java/exception/StockMasterException.java deleted file mode 100644 index 2411a374fd..0000000000 --- a/src/main/java/exception/StockMasterException.java +++ /dev/null @@ -1,31 +0,0 @@ -package exception; -public class StockMasterException extends Exception { - protected String description; - protected String type; - - public StockMasterException(String description, String type) { - this.description = description; - this.type = type; - } - - public StockMasterException() { - this.description = null; - this.type = null; - } - - public void printException() { - switch (this.type) { - case "EMPTY": - if (description.equals("description")) { - System.out.println("The item name cannot be left blank."); - } - break; - case "OUT_OF_BOUNDS": - System.out.println("The index you're accessing is out of bounds."); - break; - default: - System.out.println("Unrecognised error."); - break; - } - } -} From ca90efe1baf104db75db6a4e648eb8e37b805edc Mon Sep 17 00:00:00 2001 From: LowTL Date: Mon, 25 Mar 2024 22:28:17 +0800 Subject: [PATCH 6/7] Add command testing --- src/test/java/command/CommandTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/test/java/command/CommandTest.java diff --git a/src/test/java/command/CommandTest.java b/src/test/java/command/CommandTest.java new file mode 100644 index 0000000000..e740812c25 --- /dev/null +++ b/src/test/java/command/CommandTest.java @@ -0,0 +1,13 @@ +package command; + +import org.junit.jupiter.api.Test; + +public class CommandTest { + private Command command; + + @Test + public void command_invalidCommand_throwsError() { + + } + +} From d49ed14d9a6283ec52305506a63784aed66c6031 Mon Sep 17 00:00:00 2001 From: LowTL Date: Mon, 25 Mar 2024 22:33:41 +0800 Subject: [PATCH 7/7] Remove constants folder --- src/main/java/constants/UOM.java | 9 --------- src/main/java/constants/uomList.java | 4 ---- src/main/java/item/Item.java | 1 - 3 files changed, 14 deletions(-) delete mode 100644 src/main/java/constants/UOM.java delete mode 100644 src/main/java/constants/uomList.java diff --git a/src/main/java/constants/UOM.java b/src/main/java/constants/UOM.java deleted file mode 100644 index 7482ac6def..0000000000 --- a/src/main/java/constants/UOM.java +++ /dev/null @@ -1,9 +0,0 @@ -package constants; - -public enum UOM { - PIECE, - EA, - DOZEN, - CTN, - BOX -} diff --git a/src/main/java/constants/uomList.java b/src/main/java/constants/uomList.java deleted file mode 100644 index 8f7b74814f..0000000000 --- a/src/main/java/constants/uomList.java +++ /dev/null @@ -1,4 +0,0 @@ -package constants; - -public class uomList { -} diff --git a/src/main/java/item/Item.java b/src/main/java/item/Item.java index 7ccfb401f4..ef36256760 100644 --- a/src/main/java/item/Item.java +++ b/src/main/java/item/Item.java @@ -1,5 +1,4 @@ package item; -import constants.UOM; public class Item { public static int numberOfItems;