Question: been working this code for a store inventory for weeks and i can not get it to run package javaapplication41storeinventory; //hardwareStore.java public class hardwareStore{ }

been working this code for a store inventory for weeks and i can not get it to run

package javaapplication41storeinventory;

//hardwareStore.java public class hardwareStore{

}

import java.io.FileNotFoundException; import java.util.Scanner;

public class hardwareStoreTestProgram {

public static void main(String args[]) throws FileNotFoundException { // Load inventory text file into hardwareStore hardwareStore.loadFromFile("storeItems.txt");

// start the mainMenu mainMenu(); }

// Main menu that displays the title and 4 menu options for the user. public static void mainMenu() throws FileNotFoundException { int menuOption = 0; int itemNumber = 0; int quantity = 0; Scanner console = new Scanner(System.in);

// Loop until user chooses 4 (Exit) while (menuOption != 4) { System.out.println(" Friendly Hardware Store - Main Menu"); System.out.println("-----------------------------------"); System.out.println("1. Print Report"); System.out.println("2. Check inventory of item"); System.out.println("3. Sell item"); System.out.println("4. Exit"); System.out.println(); System.out.println("Please enter an option (1-4): ");

menuOption = console.nextInt();

// Validate user entry while (menuOption < 1 || menuOption > 4) { System.out.println(" Invalid entry, please try again."); System.out.println(" Please enter an option (1-4): "); menuOption = console.nextInt(); }

switch (menuOption) { case 1: // Print Report hardwareStore.printReport(); break; case 2: // Check inventory System.out.println(" Please enter a valid itemID to " + "check (XXXX): "); itemNumber = console.nextInt(); hardwareStore.checkForItem(itemNumber); break; case 3: // Sell item System.out.println(" Enter the itemID of them " + "item you wish to sell (ex. 4444): "); itemNumber = console.nextInt(); System.out.println(" Enter the quanitity to sell " + "(ex. 50): "); quantity = console.nextInt(); hardwareStore.sellItem(itemNumber, quantity); break; case 4: // Exit program break; }

} } }

hardwareStore.java

import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Scanner; import java.util.Vector;

public class hardwareStore {

private static Vector itemID = new Vector(); // Item ID private static Vector itemName = new Vector(); // Item Name private static Vector pOrdered = new Vector(); // Ordered private static Vector pInStore = new Vector(); // In Store private static Vector pSold = new Vector(); // Sold private static Vector manufPrice = new Vector(); // Manufacturers Price private static Vector sellingPrice = new Vector(); // Selling Price private static double totalInventory = 0; // Total Inventory worth $ private static int totalNumOfItems = 0; // Total number of inventory items

// Method that checks to see if an item is in stock and display result public static void checkForItem(int searchID) { if (itemID.contains(searchID)) { int itemIndex = itemID.indexOf(searchID); String strItemName = itemName.get(itemIndex); int totalQuantity = pInStore.get(itemIndex);

System.out.println(" There are " + totalQuantity + " " + strItemName + "(s) currently in stock."); } else { System.out.println(" Item " + searchID + " not in inventory."); } }

// Method that sells an item specified by searchID and sellQuantity params public static void sellItem(int searchID, int sellQuantity) { if (itemID.contains(searchID)) { int itemIndex = itemID.indexOf(searchID); String strItemName = itemName.get(itemIndex); int totalQuantity = pInStore.get(itemIndex); int totalSold = pSold.get(itemIndex);

if (sellQuantity > totalQuantity) { System.out.println(" Not enough quantity in store to sell " + sellQuantity + " " + strItemName + "(s)."); System.out.println(" There are only " + totalQuantity + " " + strItemName + "(s) left in stock."); } else { pInStore.set(itemIndex, (totalQuantity - sellQuantity)); pSold.set(itemIndex, (totalSold + sellQuantity)); System.out.println(" Sold " + sellQuantity + " " + strItemName + "(s)."); }

} else { System.out.println(" Item doesn't exist. Please try and enter " + "another item."); } }

// Method that sorts the vectors in parallel based on itemName Vector private static void sortVectors() { int firstOutOfOrder, location; String tempName; int tempID; int tempOrdered; int tempInStore; int tempSold; double tempManufPrice; double tempSellingPrice;

for (firstOutOfOrder = 1; firstOutOfOrder < itemName.size(); firstOutOfOrder++) {

if (itemName.elementAt(firstOutOfOrder).compareToIgnoreCase(itemName.elementAt(firstOutOfOrder - 1)) < 0) { tempName = itemName.elementAt(firstOutOfOrder); tempID = itemID.elementAt(firstOutOfOrder); tempOrdered = pOrdered.elementAt(firstOutOfOrder); tempInStore = pInStore.elementAt(firstOutOfOrder); tempSold = pSold.elementAt(firstOutOfOrder); tempManufPrice = manufPrice.elementAt(firstOutOfOrder); tempSellingPrice = sellingPrice.elementAt(firstOutOfOrder);

location = firstOutOfOrder;

do { itemName.set(location, itemName.elementAt(location - 1)); itemID.set(location, itemID.elementAt(location - 1)); pOrdered.set(location, pOrdered.elementAt(location - 1)); pInStore.set(location, pInStore.elementAt(location - 1)); pSold.set(location, pSold.elementAt(location - 1)); manufPrice.set(location, manufPrice.elementAt(location - 1)); sellingPrice.set(location, sellingPrice.elementAt(location - 1));

location--; } while (location > 0 && itemName.elementAt(location - 1).compareToIgnoreCase(tempName) > 0);

itemName.set(location, tempName); itemID.set(location, tempID); pOrdered.set(location, tempOrdered); pInStore.set(location, tempInStore); pSold.set(location, tempSold); manufPrice.set(location, tempManufPrice); sellingPrice.set(location, tempSellingPrice); } } }

// Method that loads the data from text file into vectors public static void loadFromFile(String fileName) throws FileNotFoundException { Scanner inFile = new Scanner(new FileReader(fileName)); int tempNum;

while (inFile.hasNext()) { itemID.addElement(inFile.nextInt()); inFile.nextLine();

itemName.addElement(inFile.nextLine());

tempNum = inFile.nextInt(); pOrdered.addElement(tempNum); pInStore.add(tempNum);

pSold.addElement(0);

manufPrice.addElement(inFile.nextDouble()); sellingPrice.addElement(inFile.nextDouble()); } sortVectors(); }

// Method that calculates total inventory and total number of items private static void calculateInventory() { totalNumOfItems = 0; totalInventory = 0;

for (int index = 0; index < pInStore.size(); index++) { totalNumOfItems += pInStore.elementAt(index); totalInventory += sellingPrice.elementAt(index) * pInStore.elementAt(index); } }

// Method that displays the inventory report public static void printReport() {

calculateInventory(); System.out.println(" Friendly Hardware Store " + " "); System.out.println(" " + " "); System.out.println("itemID itemName pOrdered pInStore pSold " + " manufPrice sellingPrice");

for (int index = 0; index < itemID.size(); index++) { System.out.printf("%1$-7s %2$-15s %3$-9s %4$-9s %5$-6s %6$-11.2f " + "%7$-11.2f ", itemID.elementAt(index), itemName.elementAt(index), pOrdered.elementAt(index), pInStore.elementAt(index), pSold.elementAt(index), manufPrice.elementAt(index), sellingPrice.elementAt(index)); }

System.out.printf(" Total Inventory: $%15.2f", totalInventory); System.out.println(" Total number of items in the store: " + totalNumOfItems);

} }

storeItems.txt 1111 Cooking Range 50 450.00 850.00 2222 Circular Saw 150 45.00 125.00 3333 Dish Washer 20 250.50 550.50 4444 Micro Wave 75 150.00 400.00

where am i messing up at

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!