I'm working on a program to keep track of a hardware store's inventory. For each item the item ID, item name, # of pieces ordered, # of pieces in stock, manufacturer's price and the selling price. The program must also print out a report. The program is menu driven and uses seven parallel vectors to store the information. The program must have a method to input the data into the vectors, a method to display the menu, a method to sell an item, and a method to print the report.

And I keep getting the following error messages "Illegal start of expression." Below is my code that I have so far

import java.io.*;
import java.util.*;

public class Ch10
{
  public static void main(String[] args) throws FileNotFoundException
  {
    int[]ItemIdList = new int[10];
    String[]ItmNmeList = new String[10];
    int[]PordrList = new int[10];
    int[]InStreList = new int[10];
    int[]PSldList = new int[10];
    Double[]ManuPrceList = new Double[10];
    Double[]SelPrceList = new Double[10];
    
    Scanner inFile = new Scanner(new FileReader("e:\\Ch10_Ex2Data.txt"));
    
    inputData(inFile, ItmIdList, ItmNmeList, PordrList, InStreList, PSldList, ManuPrceList, SelPrceList);
    
    sortData(ItmIdList, ItmNmeList, PordrList, InStreList, PSldList, ManuPrceList, SelPrceList);
    
    printMenu();
    printRpt();
    
    public static inputData(Scanner input, Vector<Integer> inpID, Vector<String> inpName,
        Vector<Integer> inpOrdered, Vector<Integer> inpInStore,
        Vector<Integer> inpSold, Vector<Double> inpManPrice,
        Vector<Double> inpSellPrice)
    {
      int id;
      String name;
      int order;
      double price, sellPrice;
      
      while (input.hasNext());
      {
        id = input.nextInt();
        name = input.nextLine();
        order = input.nextInt();
        price = input.nextDouble();
        sellPrice = input.nextDouble();
        
        inpID.addElement(new Integer(id));
        inpName.addElement(name);
        inpOrdered.addElement(new Integer(order));
        inpInStore.addElement(new Integer(order));
        inpSold.addElement(new Integer(0));
        inpManPrice.addElement(new Double(price));
        inpSellPrice.addElement(new Double(sellPrice));
      }
    }
    public static void printMenu()
    {
      int number;
      int index;
      
      System.out.println("Welcome to the Friendly Hardware Store");
      System.out.println("To view our available items and their quantity, press 1");
      
      number = console.nextint();
      
      if (number = 2)
        for (index=0; index<inpName.length;index++)
        
        System.out.print(" here is a current lisiting of items :" +inpName[index]);
        
        else
        System.out.println();
      
      System.out.println("To sell an item, press 3");
      System.out.println("To print a report, press 4");
      
    }
    
    //method to sell an item
    public static void sellItem()
    {
      int item;
      string name;
      int sold;
      int store;
      
      System.out.println ("Enter item number: ");
      int item = console.nextInt();
      System.out.println ("Enter the item name: ");
      String name = console.next();
      System.out.println ("Enter quantity sold: ");
      int sold = console.nextInt();
      
      public int indexOf(Object item)
    }
        
        //method to print out the report
        public static void printRpt()
        {
          int[]ItemID;
          String[] ItemName;
          int[]pOrdered;
          int[]pinStore;
          int[] pSold;
          int i,j;
          double manufPrice, sellingPrice;
          double totInventory;
          int totitems = 0;
          int totinstore = 0;
          
          system.out.println("--------------------Friendly Hardware Store"+ "--------------------\n");
          system.out.println ("ItemID " + "  ItemName         " + "pOrdered "+ " pinStore  " + " pSold " + " manufPrice  " + " sellingPrice  ");
          System.out.printf(itemID[], ItemName[], pOrdered[], pinStore[], pSold[], manufPrice[], sellingPrice[]);
          
          for (i=0; i < pSold.length; i++)
            totitems = totitems + pSold[i];
          System.out.println ("Total inventory: " + totitems);
          
          for (j=0; j < pinStore.length; j++)
            totinstore = totinstore + pinStore[j];
          System.out.println ("Total number of items in the store: " + totinstore);
        }
  }
}

Recommended Answers

All 2 Replies

Can you post the error message also ?

There are far, far more errors to that code than just the illegal start of expression warning.

Fist of all I can see a nested method declaration/definition which is illegal

Secondly your System statements aren't capitalized in some areas.

I can see many other errors such as the System.out.println printing null arrays, and doing so with the incorrect syntax.

Some identifiers aren't declared but are used, and the ones that are declared aren't used.

The main method body wasn't ended (or was in an inappropriate section of the program).

You have parameters that take Vectors, but you're passing them as arrays.

Should this program even work, the first method you call is the one after passing the Scanner object as a parameter, where you (or the rogue user) must input data continuously without really knowing what you're inputting at what time.

The list goes on, amazingly.

My suggestion? Make sure no methods are being defined within other methods, and if you're going to use Vectors you should change your arrays to Vectors in main and make many changes to your code to accommodate for them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.