diff --git a/StockMasterData.txt b/StockMasterData.txt index e69de29bb2..3a2dd251a7 100644 --- a/StockMasterData.txt +++ b/StockMasterData.txt @@ -0,0 +1,2 @@ +1. | apple iphone | Qty: 10 pieces | Cat: electronics | BuyPrice: $100.0 | SellPrice: $500.0 +2. | apple | Qty: 50 pieces | Cat: fruits | BuyPrice: $4.0 | SellPrice: $5.0 diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java index 723abe4f48..e0f66ab9b5 100644 --- a/src/main/java/storage/Storage.java +++ b/src/main/java/storage/Storage.java @@ -65,7 +65,8 @@ public static void readFromFile(String fileName) { try { Scanner scanner = new Scanner(new File(fileName)); while (scanner.hasNext()) { - String fileLine = "add" + scanner.nextLine(); + //String fileLine = "add" + scanner.nextLine(); + String fileLine = scanner.nextLine(); String[] keyCommands = fileLine.split(" \\| "); String commandQty = ""; String commandCat = ""; @@ -74,7 +75,7 @@ public static void readFromFile(String fileName) { String commandSell = ""; String commandName = ""; for (String keyCommand : keyCommands) { - if (keyCommand.contains(".")) { + if (keyCommand.contains("add")) { //do nothing. } else if (keyCommand.contains("Qty: ")) { String[] commandQtyUnit = keyCommand.replace("Qty: ", "").split(" "); @@ -88,12 +89,13 @@ public static void readFromFile(String fileName) { } else if (keyCommand.contains("SellPrice: $")) { commandSell = keyCommand.replace("SellPrice: $", ""); } else { - commandName = keyCommand; + commandName = keyCommand.trim(); } } Item toAdd = new Item(commandName, Integer.parseInt(commandQty), commandUom, commandCat, - Integer.parseInt(commandBuy), Integer.parseInt(commandSell)); + Float.parseFloat(commandBuy), Float.parseFloat(commandSell)); Itemlist.addItem(toAdd); + } scanner.close(); } catch(FileNotFoundException e) {