Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default Need Help with this page

    I have 4 different java programs that have to run with this one and i am finding errors at the bottom of the page. Any help you can provide would be ideal. I am a beginner with this, so please keep your answers simple for me.

    Java Code:
    /*
     *
     * Payroll Program - ProductInventory Class
     * Axia College - University of Phoenix
     * IT 215 - Java Programming Solution
     *
     *
     */
    
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Iterator;
    
    
    // ProductInventory Solution
    public class ProductInventory
    {
    
    
        // Define the Product Inventory Array List
        protected ArrayList<Product> myProductInventory;
    
    
        // Constructor used to initialize class parameters
        ProductInventory()
        {
    
            // Initialize the Product Inventory Array List
            myProductInventory = new ArrayList<Product>();
    
        }
    
    
        // Constructor that Accepts a Product and Places
        // it into the Inventory Array
        ProductInventory(Product pProduct)
        {
    
    		// Initialize the Product Inventory Array List
    myProductInventory = new ArrayList<Product>();
    
    // Add a user-defined Product to the inventory array
    // This Product object is placed in the first position
    // of the Product Inventory Array List
    this.addProduct(pProduct);
    
    
        }
    
    
        // Method that Computes the Overall Value of a Product Inventory Array
        public float getTotalValue()
        {
    
    		// Placeholder for the overall inventory value
    float totalInventoryValue = 0;
    
    for (Iterator it = myProductInventory.iterator(); it.hasNext(); )
    {
    
        try
        {
    
            // Get product from the product inventory array list
            Product currentProduct = (Product)it.next();
    
            // Add the total value of a Product to the overall Product inventory value
            totalInventoryValue = totalInventoryValue + (float)currentProduct.getTotalValue();
    
        }
        catch (Exception e)
        {
    
            System.out.println( e );	// Output the exception message to the display
    
        }
    
    }
    
    // Return the overall Product inventory value for the supplied Product inventory array list
    return totalInventoryValue;
    
        } // end getTotalInventoryValue method
    
    
        // Method that Sorts a Product Inventory Based on the Product Name
        public void sort()
        {
    
    
    // Sort the Product Inventory Array List (by Product Name)
    Collections.sort(myProductInventory);
    
        }
    
    
        public void addProduct(Product pProduct)
        {
    
    		// Add the new product to the product inventory array list
    myProductInventory.add(pProduct);
    
        }
    
    
        // Method that deletes a Product from the inventory
        public void deleteProduct(int pProductIndex)
        {
    
    
    // Check to See if the Inventory Array is Empty or Not
    if ( pProductIndex >= 0 && pProductIndex < getSize() )
    {
    
        // Delete/Remove the product at the index designated by the
        // pProductIndex parameter from the product inventory array list
        myProductInventory.remove(pProductIndex);
    
    }
    
    
        }
    
    
        // Method that Retrieves a Product from the Inventory
        public Product getProduct(int pProductIndex)
        {
    
    		// Return the number of Products in the inventory
            return myProductInventory.size();
    
        }
    
    
        // Method that Retrieves the Number of Products in the Inventory Array
        public int getSize()
        {
    
    
            {
           
            }
            // Check to see if a proper array index value was provided
    if ( pProductIndex >= 0 && pProductIndex < getSize() )
    {
    
        // Return the Product from the array at the specified position
        return myProductInventory.get(pProductIndex);
    
    } else {
    
        // If the provided array position is invalid,
        // return a null value as the Product
    
        return null;
    
    }
    
    
        }
    }	// end ProductInventory class solution
    Last edited by Fubarable; 09-28-2009 at 04:12 AM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hello and welcome to the forum. To help us help you I suggest that
    1) you use code tags when posting code. I have taken the liberty of editing your current post and adding the tags myself. These make your code retain its formatting making it much easier for us to read.

    and
    2) If you have any errors with compiling or running your code, please post the full error messages indicating in your code (usually with an obvious comment) which line(s) is (are) causing the error.

    Much luck!

  3. #3
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default Errors on these lines, how can i fix them.

    /*
    *
    * Payroll Program - ProductInventory Class
    * Axia College - University of Phoenix
    * IT 215 - Java Programming Solution
    *
    *
    */


    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Iterator;


    // ProductInventory Solution
    public class ProductInventory
    {


    // Define the Product Inventory Array List
    protected ArrayList<Product> myProductInventory;


    // Constructor used to initialize class parameters
    ProductInventory()
    {

    // Initialize the Product Inventory Array List
    myProductInventory = new ArrayList<Product>();

    }


    // Constructor that Accepts a Product and Places
    // it into the Inventory Array
    ProductInventory(Product pProduct)
    {

    // Initialize the Product Inventory Array List
    myProductInventory = new ArrayList<Product>();

    // Add a user-defined Product to the inventory array
    // This Product object is placed in the first position
    // of the Product Inventory Array List
    this.addProduct(pProduct);


    }


    // Method that Computes the Overall Value of a Product Inventory Array
    public float getTotalValue()
    {

    // Placeholder for the overall inventory value
    float totalInventoryValue = 0;

    for (Iterator it = myProductInventory.iterator(); it.hasNext(); )
    {

    try
    {

    // Get product from the product inventory array list
    Product currentProduct = (Product)it.next();

    // Add the total value of a Product to the overall Product inventory value
    totalInventoryValue = totalInventoryValue + (float)currentProduct.getTotalValue();

    }
    catch (Exception e)
    {

    System.out.println( e ); // Output the exception message to the display

    }

    }

    // Return the overall Product inventory value for the supplied Product inventory array list
    return totalInventoryValue;

    } // end getTotalInventoryValue method


    // Method that Sorts a Product Inventory Based on the Product Name
    public void sort()
    {


    // Sort the Product Inventory Array List (by Product Name)
    Collections.sort(myProductInventory);

    }


    public void addProduct(Product pProduct)
    {

    // Add the new product to the product inventory array list
    myProductInventory.add(pProduct);

    }


    // Method that deletes a Product from the inventory
    public void deleteProduct(int pProductIndex)
    {


    // Check to See if the Inventory Array is Empty or Not
    if ( pProductIndex >= 0 && pProductIndex < getSize() )
    {

    // Delete/Remove the product at the index designated by the
    // pProductIndex parameter from the product inventory array list
    myProductInventory.remove(pProductIndex);

    }


    }


    // Method that Retrieves a Product from the Inventory
    public Product getProduct(int pProductIndex)
    {

    // Return the number of Products in the inventory
    return myProductInventory.size(); (recieved an error here)

    }


    // Method that Retrieves the Number of Products in the Inventory Array
    public int getSize()
    {


    {

    }
    // Check to see if a proper array index value was provided
    if ( pProductIndex >= 0 && pProductIndex < getSize() )(recieved an error here)
    {

    // Return the Product from the array at the specified position
    return myProductInventory.get(pProductIndex);(recieved an error here)

    } else {

    // If the provided array position is invalid,
    // return a null value as the Product

    return null;(recieved an error here)

    }


    }(recieved an error here)


    // end ProductInventory class solution

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Go back to previous page using session in JSP page
    By gopikarikati009 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-23-2011, 10:30 AM
  2. Web Page
    By coder_java_ in forum AWT / Swing
    Replies: 7
    Last Post: 11-14-2008, 07:55 AM
  3. setting the view to a jsp page from a self refeshing page
    By deepal_205 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-15-2008, 04:41 PM
  4. Replies: 21
    Last Post: 08-01-2008, 11:13 AM
  5. warning that page has expired and i need to refresh the page again
    By 82rathi.angara in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 07-15-2008, 01:48 PM

Posting Permissions

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