Skip to content

Commit

Permalink
Merge pull request #98 from Joellimjr/v2.0
Browse files Browse the repository at this point in the history
add addcommand sequence diagram
  • Loading branch information
Joellimjr committed Apr 3, 2024
2 parents 615a5ce + 1e37847 commit 8fb8256
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 17 deletions.
6 changes: 2 additions & 4 deletions StockMasterData.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
1. | apple iphone | Qty: 10 pieces | Cat: electronics | BuyPrice: $100.0 | SellPrice: $500.0
2. | apple | Qty: 180 pieces | Cat: fruits | BuyPrice: $4.0 | SellPrice: $5.0
3. | orange | Qty: 0 pieces | Cat: fruits | BuyPrice: $2.0 | SellPrice: $4.0
4. | samsung phone | Qty: 3 pieces | Cat: electronics | BuyPrice: $80.0 | SellPrice: $300.0
1. | testItem | Qty: 1 EA | Cat: null | BuyPrice: $1.0 | SellPrice: $10.0
2. | testItem | Qty: 1 EA | Cat: null | BuyPrice: $1.0 | SellPrice: $10.0
Binary file added docs/Diagrams/AddCommand_Sequence_Diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ Example of usage:
del Apples
```

### Selling an item: `sell`
Sells a quantity of an item from the list of items at a stated price.

Format: `sell [ITEM_NAME] qty/[SELL_QUANTITY] price/[SELL_PRICE]`

* `SELL_PRICE` is an optional field. If blank, it will default to the item's set sell price.

Example of usage:
```
sell Apple qty/20 price/6
sell Phone qty/1
```

### Editing an item: `edit`
Edits the parameters of the item.

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ public class AddCommand extends Command {
public static final String MESSAGE_SUCCESS = "added: ";
protected String itemName;
protected int quantity;
protected String uom;
protected String UnitOfMeasurement;
protected String category;
protected float buyPrice;
protected float sellPrice;
private final Item toAdd;

public AddCommand(String itemName, int quantity, String uom, String category, float buyPrice, float sellPrice) {
public AddCommand(String itemName, int quantity, String UnitOfMeasurement, String category, float buyPrice, float sellPrice) {
this.itemName = itemName;
this.quantity = quantity;
this.uom = uom;
this.UnitOfMeasurement = UnitOfMeasurement;
this.category = category;
this.buyPrice = buyPrice;
this.sellPrice = sellPrice;
this.toAdd = new Item(itemName, quantity, uom, category, buyPrice, sellPrice);
this.toAdd = new Item(itemName, quantity, UnitOfMeasurement, category, buyPrice, sellPrice);
}

public String getItemName() {
Expand All @@ -34,8 +34,8 @@ public int getQuantity() {
public String getCategory() {
return category;
}
public String getUom() {
return uom;
public String getUnitOfMeasurement() {
return UnitOfMeasurement;
}
public float getBuyPrice() {
return buyPrice;
Expand All @@ -50,7 +50,7 @@ public void execute() {
updateQuantity(itemName);
} else {
Itemlist.addItem(toAdd);
System.out.print(MESSAGE_SUCCESS + getItemName() + " (Qty: " + getQuantity() + " " + getUom() +
System.out.print(MESSAGE_SUCCESS + getItemName() + " (Qty: " + getQuantity() + " " + getUnitOfMeasurement() +
", Buy: $" + getBuyPrice() + ", Sell: $" + getSellPrice() + ")");
Storage.addToFile(Itemlist.getItems());
if (!category.equals("NA")) {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/command/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ public EditCommand(String itemName, String newItemName, int newQuantity, String
this.newSellPrice = newSellPrice;
}

public String getItemName() {
return itemName;
}

public String getNewItemName() {
return newItemName;
}

public int getNewQuantity() {
return newQuantity;
}

public String getNewUnitOfMeasurement() {
return newUnitOfMeasurement;
}

public String getNewCategory() {
return newCategory;
}

public float getNewBuyPrice() {
return newBuyPrice;
}

public float getNewSellPrice() {
return newSellPrice;
}

@Override
public void execute() {
int index = -1; // flag to check if item exists in Itemlist
Expand Down Expand Up @@ -77,4 +105,5 @@ public void execute() {
ui.TextUi.replyToUser("");
Storage.overwriteFile(Itemlist.getItems());
}

}
9 changes: 9 additions & 0 deletions src/main/java/command/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public FindCommand(String itemInfo, String keyword) {
this.itemInfo = itemInfo;
}

public String getItemInfo() {
return keyword;
}

public String getKeyword() {
return itemInfo;
}

@Override
public void execute() {
if (itemInfo.equals("NA")) {
Expand Down Expand Up @@ -52,4 +60,5 @@ public ArrayList<String> filterList() {
}
return searchList;
}

}
5 changes: 5 additions & 0 deletions src/main/java/command/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public ListCommand(ArrayList<Item> arrayList, String category, boolean isListMar
this.isListMarked = isListMarked;
}

public String getCategory() {
return category;
}

//@@author Fureimi
public void execute() {
if (category.equals("NA") && !isListMarked) {
Expand All @@ -25,5 +29,6 @@ public void execute() {
TextUi.showCustomizedList(arrayList, category, isListMarked);
}
}

}

5 changes: 5 additions & 0 deletions src/main/java/command/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public MarkCommand(String itemName) {
this.itemName = itemName;
}

public String getItemName() {
return itemName;
}

@Override
public void execute() throws CommandFormatException {
Item item = Itemlist.getItem(itemName);
Expand All @@ -27,4 +31,5 @@ public void execute() throws CommandFormatException {
}
Storage.overwriteFile(Itemlist.getItems());
}

}
13 changes: 13 additions & 0 deletions src/main/java/command/SellCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public SellCommand (String itemName, int quantity, float price) {
this.sellPrice = price;
}

public String getItemName() {
return itemName;
}

public int getSellQuantity() {
return sellQuantity;
}

public float getSellPrice() {
return sellPrice;
}

@Override
public void execute() {
int index = -1;
Expand Down Expand Up @@ -49,4 +61,5 @@ public void execute() {
Cashier.addItem(newTransaction);
TransactionLogs.addToLog(Cashier.getTransactions());
}

}
5 changes: 5 additions & 0 deletions src/main/java/command/UnmarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public UnmarkCommand(String itemName) {
this.itemName = itemName;
}

public String getItemName() {
return itemName;
}

@Override
public void execute() throws CommandFormatException {
Item item = Itemlist.getItem(itemName);
Expand All @@ -27,4 +31,5 @@ public void execute() throws CommandFormatException {
}
Storage.overwriteFile(Itemlist.getItems());
}

}
22 changes: 22 additions & 0 deletions src/test/java/command/SellCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command;

import exceptions.CommandFormatException;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.fail;

public class SellCommandTest {

@Test
public void sellItemTest() throws CommandFormatException {
try {
Command sellCommandTest1 = new SellCommand("testItem", 1, 3);
Command sellCommandTest2 = new SellCommand("testItem", 7, 14);
sellCommandTest1.execute();
sellCommandTest2.execute();
} catch (CommandFormatException e) {
fail("Unable to sell item.");
}
}

}
99 changes: 93 additions & 6 deletions src/test/java/parser/ParserTest.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,109 @@
package parser;

import command.Command;
import command.AddCommand;
import command.EditCommand;
import command.FindCommand;
import command.HelpCommand;
import command.ListCommand;
import command.MarkCommand;
import command.SellCommand;
import command.UnmarkCommand;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class ParserTest {

private Parser parser;

@BeforeEach
public void setUp() {
parser = new Parser();
}

/*
* Note how the names of the test methods does not follow the normal naming convention.
* That is because our coding standard allows a different naming convention for test methods.
*/
@Test
public void testParseAddCommand() {
String userInput = "add ItemName qty/10 /unitOfMeasurement cat/Category buy/10.5 sell/15.0";
Command command = parser.parseInput(userInput);
assertInstanceOf(AddCommand.class, command);
AddCommand addCommand = (AddCommand) command;
assertEquals("ItemName", addCommand.getItemName());
assertEquals(10, addCommand.getQuantity());
assertEquals("unitOfMeasurement", addCommand.getUnitOfMeasurement());
assertEquals("Category", addCommand.getCategory());
assertEquals(10.5f, addCommand.getBuyPrice(), 0.01);
assertEquals(15.0f, addCommand.getSellPrice(), 0.01);
}

@Test
public void testParseEditCommand() {
String userInput = "edit ItemName name/NewName qty/20 uom/NewUOM cat/NewCategory buy/15.0 sell/20.0";
Command command = parser.parseInput(userInput);
assertInstanceOf(EditCommand.class, command);
EditCommand editCommand = (EditCommand) command;
assertEquals("ItemName", editCommand.getItemName());
assertEquals("NewName", editCommand.getNewItemName());
assertEquals(20, editCommand.getNewQuantity());
assertEquals("NewUOM", editCommand.getNewUnitOfMeasurement());
assertEquals("NewCategory", editCommand.getNewCategory());
assertEquals(15.0f, editCommand.getNewBuyPrice(), 0.01);
assertEquals(20.0f, editCommand.getNewSellPrice(), 0.01);
}

@Test
public void testParseSellCommand() {
String userInput = "sell ItemName qty/5 price/20.0";
Command command = parser.parseInput(userInput);
assertInstanceOf(SellCommand.class, command);
SellCommand sellCommand = (SellCommand) command;
assertEquals("ItemName", sellCommand.getItemName());
assertEquals(5, sellCommand.getSellQuantity());
assertEquals(20.0f, sellCommand.getSellPrice(), 0.01);
}

@Test
public void testParseFindCommand() {
String userInput = "find /info Keyword";
Command command = parser.parseInput(userInput);
assertInstanceOf(FindCommand.class, command);
FindCommand findCommand = (FindCommand) command;
assertEquals("/info", findCommand.getItemInfo());
assertEquals("Keyword", findCommand.getKeyword());
}

@Test
public void testParseListCommand() {
String userInput = "list cat/Category";
Command command = parser.parseInput(userInput);
assertInstanceOf(ListCommand.class, command);
ListCommand listCommand = (ListCommand) command;
assertEquals("Category", listCommand.getCategory());
}

@Test
public void testParseMarkCommand() {
String userInput = "mark ItemName";
Command command = parser.parseInput(userInput);
assertInstanceOf(MarkCommand.class, command);
MarkCommand markCommand = (MarkCommand) command;
assertEquals("ItemName", markCommand.getItemName());
}

@Test
public void testParseUnmarkCommand() {
String userInput = "unmark ItemName";
Command command = parser.parseInput(userInput);
assertInstanceOf(UnmarkCommand.class, command);
UnmarkCommand unmarkCommand = (UnmarkCommand) command;
assertEquals("ItemName", unmarkCommand.getItemName());
}

@Test
public void parse_emptyInput_returnsIncorrect() {
public void testParseHelpCommand() {
String userInput = "help";
Command command = parser.parseInput(userInput);
assertInstanceOf(HelpCommand.class, command);
}
}
}

0 comments on commit 8fb8256

Please sign in to comment.