Results 1 to 2 of 2
  1. #1
    tlouvierre is offline Member
    Join Date
    Apr 2009
    Location
    I live Stafford Texas right outside of Houston.
    Posts
    78
    Rep Power
    0

    Default E:\IT 215 Java Programming\Inventory.java:211: reached end of file while parsing

    Java Code:
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.text.*;
    
    public class Inventory
    {
    // This constant is the max # of inventory items:
    public static final int maxItems = 10000;
    
    // main() method begins execution of a Java application:
    public static void main( String args[] )
    {
    // This flag will control whether we exit the loop below:
    boolean stop = false;
    
    // This array will hold the entire inventory:
    ProductWithLength inventory[] = new ProductWithLength[maxItems];
    
    // This counter will count the number of items in the inventory:
    int numItems = 0;
    
    // Loop until user indicates to exit the app:
    while (!stop)
    {
    // Show title, and read product number and store in memory:
    String itemNumber =
    JOptionPane.showInputDialog("Office Supply Inventory Program.\n\n " +
    "Please enter a new product number or press Cancel to end this program: "
    );
    
    // Check for user clicking Cancel:
    if (itemNumber == null)
    {
    // User clicked Cancel, set flag so we'll exit:
    stop = true;
    }
    else
    {
    // User did not click Cancel, so continue reading info for this iteration...
    
    float unitAmount = -1; // Number of units
    String unitAmountStr = ""; // String representation of # of units
    float price = -1; // Price of unit
    String priceStr = ""; // String representation of price
    float value; // Value of units multiplied by price
    int length = -1; // Length of product
    String lengthStr = ""; // String representation of length
    
    // Prompt for and read product name:
    String productName =
    JOptionPane.showInputDialog("Please enter the product name:\n\n");
    
    // Prompt for and read number of units, until a positive
    // value is entered:
    while (unitAmount <= 0)
    {
    unitAmountStr = JOptionPane.showInputDialog(
    "Please enter the number of units (value must be greater than 0):\n\n");
    
    try
    {
    unitAmount = Float.parseFloat(unitAmountStr);
    }
    catch(Exception ex)
    {
    }
    }
    
    // Prompt for and read price per unit, until a positive
    // value is entered:
    while (price <= 0)
    {
    priceStr = JOptionPane.showInputDialog(
    "Please enter the price per unit (value must be greater than 0):\n\n");
    
    try
    {
    price = Float.parseFloat(priceStr);
    }
    catch(Exception ex)
    {
    }
    }
    
    // Prompt for and read length, until a positive
    // value is entered:
    while (length <= 0)
    {
    lengthStr = JOptionPane.showInputDialog(
    "Please enter the length per unit (value must be greater than 0):\n\n");
    
    try
    {
    length = Integer.parseInt(lengthStr);
    }
    catch(Exception ex)
    {
    }
    }
    
    // Now we know units, price and length are positive values.
    
    // Instantiate a ProductWithLength to hold this inventory item:
    ProductWithLength p1 =
    new ProductWithLength(itemNumber, productName, unitAmount, price, length);
    
    // Add this Product to the inventory array:
    inventory[numItems] = p1;
    
    // Increment item counter:
    numItems++;
    }
    }
    
    // User has indicated to exit application...
    
    // Check for empty inventory:
    if (numItems == 0)
    {
    // No products in inventory...
    JOptionPane.showMessageDialog(null,
    "No products were entered into the inventory.\n" +
    "Unable to display output.",
    "No Products Entered",
    JOptionPane.ERROR_MESSAGE);
    }
    else
    {
    // There are some products in inventory...
    
    // Trim the inventory array of all but actual Product objects:
    inventory = trimInventoryArray(inventory, numItems);
    
    // Sort the inventory array by product name:
    sortInventoryByName(inventory);
    
    // Display output for entire inventory...
    JOptionPane.showMessageDialog(null,
    "Thank you for your input.\n" +
    "Please press OK for inventory display.",
    "Stop Request Received",
    JOptionPane.INFORMATION_MESSAGE);
    
    // Loop through inventory items and display info about each:
    for (int i=0; i < numItems; i++)
    {
    JOptionPane.showMessageDialog(
    null,
    // Product info:
    "Product Number: " + inventory[i].getitemNumber() + "\n" + // product #
    "Product Name: " + inventory[i].getproductName() + "\n" + // product name
    "Units in stock: " + inventory[i].getunitAmount() + "\n" + // # units
    "Length: " + inventory[i].getLength() + "\n" + // length
    String.format("Price of each unit: $%,.2f\n", inventory[i].getunitPrice()) + // unit price
    String.format("Restocking fee: $%,.2f\n", inventory[i].getRestockingFee()) + // restocking fee
    String.format("Inventory value is $%,.2f\n", inventory[i].calculateValue()), // inventory value
    "Item #" + (i+1) + " of " + numItems, // this is the window title
    JOptionPane.INFORMATION_MESSAGE);
    }
    
    // Display total inventory value:
    JOptionPane.showMessageDialog(null,
    String.format("Value of entire inventory is $%,.2f\n", Inventory.calcEntireValue(inventory, numItems)),
    "Total Inventory Value",
    JOptionPane.INFORMATION_MESSAGE);
    }
    
    // Display ending message:
    JOptionPane.showMessageDialog(null,
    "Thank you for using the Office Supply Inventory Program!",
    "Adios!",
    JOptionPane.PLAIN_MESSAGE);
    
    } // end method main
    
    // Trim inventory array to specified size:
    public static ProductWithLength[] trimInventoryArray(ProductWithLength[] inventory, int numItems)
    {
    ProductWithLength[] returnVal = new ProductWithLength[numItems];
    
    for (int i=0; i < numItems; i++)
    {
    returnVal[i] = inventory[i];
    }
    
    return returnVal;
    }
    
    // Calculate the value of the entire inventory.
    public static float calcEntireValue(Product[] inven, int numItems)
    {
    float value = 0;
    
    // Loop through products and add their values to the total:
    for (int i=0; i < numItems; i++)
    {
    value += inven[i].calculateValue();
    }
    
    return value;
    }
    
    // Sort the inventory array by product name:
    public static void sortInventoryByName(Product[] inven)
    {
    Arrays.sort(inven);
    }
    }
     // end class Inventory
    __________________________________________________
    I thought when it said "reached end of file while parsing" it meant that there was} missing but if I add one I get the same error. What do I do next?:(
    Heeellloo, How are you today? Yah, no one has comments on how my programs are. If they are intelligent, sophistocated, eligant etc. I could use a pick me up just like you.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    I thought when it said "reached end of file while parsing" it meant that there was} missing
    Yes, it usually means you've misplaced a curley brace.

    but if I add one I get the same error.
    The crucial thing to determine is where to make the change.

    What do I do next?
    Some suggestions/possibilities:
    1 format your code. The style of formatting may not be important but consistency is vital. Making a good habit now will make writing code much easier later. This requires patience and determination.
    2 commentout or remove large blocks of code, eg, methods and inner classes, and recompile as you go.
    3 start a new file and slowly add code blocks and recompile as you go.

Similar Threads

  1. Replies: 16
    Last Post: 05-28-2009, 03:41 PM
  2. Replies: 14
    Last Post: 05-28-2009, 05:44 AM
  3. Replies: 6
    Last Post: 05-14-2008, 04:04 AM
  4. signaling file(s) have reached in directory
    By ashu261 in forum Advanced Java
    Replies: 0
    Last Post: 02-04-2008, 07:45 AM
  5. put a flash file in java programming?
    By notherand in forum New To Java
    Replies: 2
    Last Post: 01-23-2008, 04:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •