Results 1 to 4 of 4
Thread: Need Help with this page
- 09-28-2009, 04:04 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
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 solutionLast edited by Fubarable; 09-28-2009 at 04:12 AM. Reason: code tags added
-
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!
- 09-28-2009, 06:26 PM #3
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
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
-
If you completely ignore previous suggestions, then why should we be motivated to put in effort to help you further?
Similar Threads
-
Go back to previous page using session in JSP page
By gopikarikati009 in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 06-23-2011, 10:30 AM -
Web Page
By coder_java_ in forum AWT / SwingReplies: 7Last Post: 11-14-2008, 07:55 AM -
setting the view to a jsp page from a self refeshing page
By deepal_205 in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 08-15-2008, 04:41 PM -
i click on it,then first time error page comes,second time click then product page co
By 82rathi.angara in forum New To JavaReplies: 21Last Post: 08-01-2008, 11:13 AM -
warning that page has expired and i need to refresh the page again
By 82rathi.angara in forum JavaServer Pages (JSP) and JSTLReplies: 5Last Post: 07-15-2008, 01:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks