Inventory Program Part 2

errors in Inventory Program Part 2

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 9479 Views - Last Post: 20 June 2008 - 06:42 PM Rate Topic: -----

#1 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Inventory Program Part 2

Post icon  Posted 19 June 2008 - 10:24 AM

Please help, I am really lost on this program, here is the code I have and the error states "C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\Inventory.java:61: '}' expected" this is for line 60 of the code.






/* 
 * 
 */
// Import class to format values into currency
	import java.text.DecimalFormat;
/** 
 * 
 * @author Tammy
 */

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];
	
	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;
	
	// Add a product to array, adds to first empty slot found
 public void addProduct (Product item){
		
	 for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item;
				return;
			}
		}
 }
	
   /* Loop through array and add up the total value
	* Add quantity on hand and multiply by its price
	* Add the value to a running total
	*/
 
	public double getTotalInvValue(){
		double sumOfInventory = 0.0;
		
		for (Product item : items) {
		   
			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}
	
	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");
		
		boolean hasItems = false;
		
		for (Product item : items) {
			if (item!= null) {
				hasItems = true;
				
				System.out.println("Inventory is currently empty.\n"); 
			}
							
		


Please let me know if you need all of the code for this assignment, as I am not sure. This is the part of the code that keeps giving me one error when I try to build the main project. Thanks for the help.

Is This A Good Question/Topic? 0
  • +

Replies To: Inventory Program Part 2

#2 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 10:43 AM

Sorry, I am new to this. This assignment is to modify the Inventory Program so the application can handle multiple items and use an array to store the items. The output should display the information one product at a time; including the item number, name of the product, the number of units in stock, the price of each unity, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory. Create a method to calculate the value of the entire inventory. Create another method to sort the array items by the name of the product.
Was This Post Helpful? 0
  • +
  • -

#3 rgfirefly24  Icon User is online

  • D.I.C Lover
  • member icon


Reputation: 283
  • View blog
  • Posts: 1,494
  • Joined: 07-April 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 11:24 AM

you are missing a closing bracket somewhere in your code. What i would suggest is go through your code line by line. Find every opening brace and then find its counterpart. Also you can post your code in full that way we can look at everything.
Was This Post Helpful? 1
  • +
  • -

#4 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 02:11 PM

Here is all of the code I have for the Inventory Program Part 2, thanks for looking at it for me.
/* Inventory Program
 * This program displays product information: product number, name, number of
 * units in stock, price of each unit, and the value of the inventory.
 * 
 */

package mydvdsjava;

import java.util.Scanner;

/** Inventory Program
 * IT 215
 * @author Tammy Fica
 * June 13, 2008
 */
public class MyDvds{
   
  
	//main method begins execution of Java application
	/**
	 * @param args the command line arguments
	 */
	
	public static void main(String[] args) {

		//create and initialize a DVD object
		DVD dvd = new DVD(); //invokes constructor
	   
		//create Scanner to obtain input from command window
		Scanner input = new Scanner( System.in);
		
		System.out.print("Enter product name, item number, number of units in stock, and price of each unit"); 
		// prompt for user input
		
		String title = "get this from input";
		
		double stock = 0.0; 
		double price = 0.0; 
		double item = 0.0; 
		dvd = new DVD(title, price, stock, item);
		
		System.out.println(dvd);
		
		System.out.println("Title is: " + dvd.getTitle());
		System.out.println("The item number is: " + dvd.getDVDNumber());
		System.out.println("The number of units in stock is: " + dvd.getDVDStock());
		System.out.println("The price of each unit is: " + dvd.getDVDPrice());
		System.out.println("The value of inventory is: " + dvd.inventoryValue());
  
		} //end method main
		
} //end classMyDvds



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Tammy
 */
class Product {
	
	private String name;
	private int quantity;
	private double price;
	private int productid = 0;
	
	// Set the default state of object
	
	public Product() {
		this (0,"Unknown", 0, 0.00);
	}
	
	// Constructor to specify name, quantity, and price for items
	public Product (int productId, String itemname, int quantityOnHand, double itemprice) {
		productid = productId;
		setName (itemname);
		setQuantityOnHand (quantityOnHand);
		setPrice (itemprice);
		
	}
	public void setName(String itemname) {
		name = itemname;
		}
	
	// Sets quantity on hand and defaults to zero, if negative
	public void setQuantityOnHand (int quantityOnHand) {
		if (quantityOnHand > 0) {
			quantity = quantityOnHand;
			}
		else { quantity = 0; }
		
	}
	// Set price of product and default to zero if negative
	public void setPrice (double itemPrice) {
		if (itemPrice > 0.00) {
			price = itemPrice;
			}
		else { price = 0.00; }
		
	}
	
	// Get product name
	public String getName() {
		return name;
		}
	
	public int getQuantityOnHand() {
		return quantity;
		
	}
	
	public double getPrice() {
		return price;
	}
	
	// Calculate value of stock on this item
	public double getItemValue() {
		return (price * (double)quantity);
	}
	
	@Override
	public String toString() {
		return name + "-" + price;
	}
	
}
  


 * 
 */
// Import class to format values into currency
	import java.text.DecimalFormat;
/** 
 * 
 * @author Tammy
 */

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];
	
	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;
}
	// Add a product to array, adds to first empty slot found
public void addProduct (Product item) {
		
	 for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item;
				return;
			
			}
	 }
}
 
	
   /* Loop through array and add up the total value
	* Add quantity on hand and multiply by its price
	* Add the value to a running total
	*/
 
	public double getTotalInvValue(){
		double sumOfInventory = 0.0;
		
		for (Product item : items) {
		   
			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}
	
	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");
		
		boolean hasItems = false;
		
		for (Product item : items) {
			if (item!= null)  {
				hasItems = true; 
				  System.out.println("Inventory is currently empty.\n"); }
		   
	  


Here is the error message when I try to build.

C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\Inventory.java:21: 'class' or 'interface' expected
public void addProduct (Product item) {
1 error
BUILD FAILED (total time: 0 seconds)



Thank you for any comments and suggestions, I am very confused.
Was This Post Helpful? 0
  • +
  • -

#5 rgfirefly24  Icon User is online

  • D.I.C Lover
  • member icon


Reputation: 283
  • View blog
  • Posts: 1,494
  • Joined: 07-April 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 02:58 PM

ok here is your problem. Once i put all the brackets on their own line i saw it.

public class Inventory 
{
    // Set up an array 0f Products
    int inventorySize = 30;
    private Product items[] = new Product[InventorySize];

    // Set formatter to format values into currency
    DecimalFormat formatter = new DecimalFormat("$###,###.00");
    private int InventorySize;
}//this is closing your class too early remove it :)/>
    // Add a product to array, adds to first empty slot found



once you fix that and place all the ending brackets you need on inventory.java you should do just fine
Was This Post Helpful? 1
  • +
  • -

#6 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 03:14 PM

View Postrgfirefly24, on 19 Jun, 2008 - 02:58 PM, said:

ok here is your problem. Once i put all the brackets on their own line i saw it.

public class Inventory 
{
    // Set up an array 0f Products
    int inventorySize = 30;
    private Product items[] = new Product[InventorySize];

    // Set formatter to format values into currency
    DecimalFormat formatter = new DecimalFormat("$###,###.00");
    private int InventorySize;
}//this is closing your class too early remove it :)/>
    // Add a product to array, adds to first empty slot found



once you fix that and place all the ending brackets you need on inventory.java you should do just fine

Was This Post Helpful? 0
  • +
  • -

#7 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 03:22 PM

View Postjavagreenhorn, on 19 Jun, 2008 - 03:14 PM, said:

View Postrgfirefly24, on 19 Jun, 2008 - 02:58 PM, said:

ok here is your problem. Once i put all the brackets on their own line i saw it.

 * June 13, 2008
 */
public class MyDvds{
   
  
    //main method begins execution of Java application
    /**
     * @param args the command line arguments
     */
    
    public static void main(String[] args) {

        //create and initialize a DVD object
        DVD dvd = new DVD(); //invokes constructor
       
        //create Scanner to obtain input from command window
        Scanner input = new Scanner( System.in);
        
        System.out.print("Enter product name, item number, number of units in stock, and price of each unit"); 
        // prompt for user input
        
        String title = "get this from input";
        
        double stock = 0.0; 
        double price = 0.0; 
        double item = 0.0; 
        dvd = new DVD(title, price, stock, item);
        
        System.out.println(dvd);
        
        System.out.println("Title is: " + dvd.getTitle());
        System.out.println("The item number is: " + dvd.getDVDNumber());
        System.out.println("The number of units in stock is: " + dvd.getDVDStock());
        System.out.println("The price of each unit is: " + dvd.getDVDPrice());
        System.out.println("The value of inventory is: " + dvd.inventoryValue());
  
        } //end method main
        
} //end classMyDvds





public class Inventory 
{
    // Set up an array 0f Products
    int inventorySize = 30;
    private Product items[] = new Product[InventorySize];

    // Set formatter to format values into currency
    DecimalFormat formatter = new DecimalFormat("$###,###.00");
    private int InventorySize;
}//this is closing your class too early remove it :)/>
    // Add a product to array, adds to first empty slot found



once you fix that and place all the ending brackets you need on inventory.java you should do just fine





Thanks so much for your help! I have done what you suggested and this is where I stand right now. When I build I get two errors. Here is my code and errors.

/* 
 * 
 */
// Import class to format values into currency
	import java.text.DecimalFormat;
/** 
 * 
 * @author Tammy
 */

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];
	
	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;

	// Add a product to array, adds to first empty slot found
public void addProduct (Product Item) {
		Product item;

	 for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item;
				return;
			
			}
	 }
}
 
	
   /* Loop through array and add up the total value
	* Add quantity on hand and multiply by its price
	* Add the value to a running total
	*/
 
	public double getTotalInvValue(){
		double sumOfInventory = 0.0;
		
		for (Product item : items) {
		   
			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}
	
	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");
		
		boolean hasItems = false;
		
		for (Product item : items) {
			if (item!= null)  {
				hasItems = true; 
				  System.out.println("Inventory is currently empty.\n"); }
		}
	}
}   
	   
			


 * @author Tammy
 */
class Product {
	
	private String name;
	private int quantity;
	private double price;
	private int productid = 0;
	
	// Set the default state of object
	
	public Product() {
		this (0,"Unknown", 0, 0.00);
	}
	
	// Constructor to specify name, quantity, and price for items
	public Product (int productId, String itemname, int quantityOnHand, double itemprice) {
		productid = productId;
		setName (itemname);
		setQuantityOnHand (quantityOnHand);
		setPrice (itemprice);
		
	}
	public void setName(String itemname) {
		name = itemname;
		}
	
	// Sets quantity on hand and defaults to zero, if negative
	public void setQuantityOnHand (int quantityOnHand) {
		if (quantityOnHand > 0) {
			quantity = quantityOnHand;
			}
		else { quantity = 0; }
		
	}
	// Set price of product and default to zero if negative
	public void setPrice (double itemPrice) {
		if (itemPrice > 0.00) {
			price = itemPrice;
			}
		else { price = 0.00; }
		
	}
	
	// Get product name
	public String getName() {
		return name;
		}
	
	public int getQuantityOnHand() {
		return quantity;
		
	}
	
	public double getPrice() {
		return price;
	}
	
	// Calculate value of stock on this item
	public double getItemValue() {
		return (price * (double)quantity);
	}
	
	@Override
	public String toString() {
		return name + "-" + price;
	}
	
}
  






These are the errors that I am getting,

C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\Inventory.java:14: illegal forward reference
private Product items[] = new Product[InventorySize];
C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\mydvdsjava\MyDvds.java:27: cannot access mydvdsjava.DVD
bad class file: C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\build\classes\mydvdsjava\DVD.class
class file contains wrong class: mydvdsjava.dvd
Please remove or make sure it appears in the correct subdirectory of the classpath.
DVD dvd = new DVD(); //invokes constructor
2 errors
BUILD FAILED (total time: 1 second)


I do not know what I am doing wrong here.
Was This Post Helpful? 0
  • +
  • -

#8 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 03:31 PM

View Postjavagreenhorn, on 19 Jun, 2008 - 03:22 PM, said:

View Postjavagreenhorn, on 19 Jun, 2008 - 03:14 PM, said:

View Postrgfirefly24, on 19 Jun, 2008 - 02:58 PM, said:

ok here is your problem. Once i put all the brackets on their own line i saw it.

 * June 13, 2008
 */
public class MyDvds{
   
  
    //main method begins execution of Java application
    /**
     * @param args the command line arguments
     */
    
    public static void main(String[] args) {

        //create and initialize a DVD object
        DVD dvd = new DVD(); //invokes constructor
       
        //create Scanner to obtain input from command window
        Scanner input = new Scanner( System.in);
        
        System.out.print("Enter product name, item number, number of units in stock, and price of each unit"); 
        // prompt for user input
        
        String title = "get this from input";
        
        double stock = 0.0; 
        double price = 0.0; 
        double item = 0.0; 
        dvd = new DVD(title, price, stock, item);
        
        System.out.println(dvd);
        
        System.out.println("Title is: " + dvd.getTitle());
        System.out.println("The item number is: " + dvd.getDVDNumber());
        System.out.println("The number of units in stock is: " + dvd.getDVDStock());
        System.out.println("The price of each unit is: " + dvd.getDVDPrice());
        System.out.println("The value of inventory is: " + dvd.inventoryValue());
  
        } //end method main
        
} //end classMyDvds





public class Inventory 
{
    // Set up an array 0f Products
    int inventorySize = 30;
    private Product items[] = new Product[InventorySize];

    // Set formatter to format values into currency
    DecimalFormat formatter = new DecimalFormat("$###,###.00");
    private int InventorySize;
}//this is closing your class too early remove it :)/>
    // Add a product to array, adds to first empty slot found



once you fix that and place all the ending brackets you need on inventory.java you should do just fine





Thanks so much for your help! I have done what you suggested and this is where I stand right now. When I build I get two errors. Here is my code and errors.

 * June 13, 2008
 */
public class MyDvds{
   
  
	//main method begins execution of Java application
	/**
	 * @param args the command line arguments
	 */
	
	public static void main(String[] args) {

		//create and initialize a DVD object
		DVD dvd = new DVD(); //invokes constructor	  
	   //create Scanner to obtain input from command window
		Scanner input = new Scanner( System.in);
		
		System.out.print("Enter product name, item number, number of units in stock, and price of each unit"); 
		// prompt for user input
		
		String title = "get this from input";
		
		double stock = 0.0; 
		double price = 0.0; 
		double item = 0.0; 
		dvd = new DVD(title, price, stock, item);
		
		System.out.println(dvd);
		
		System.out.println("Title is: " + dvd.getTitle());
		System.out.println("The item number is: " + dvd.getDVDNumber());
		System.out.println("The number of units in stock is: " + dvd.getDVDStock());
		System.out.println("The price of each unit is: " + dvd.getDVDPrice());
		System.out.println("The value of inventory is: " + dvd.inventoryValue());
  
		} //end method main
		
} //end classMyDvds




/* 
 * 
 */
// Import class to format values into currency
	import java.text.DecimalFormat;
/** 
 * 
 * @author Tammy
 */

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];
	
	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;

	// Add a product to array, adds to first empty slot found
public void addProduct (Product Item) {
		Product item;

	 for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item;
				return;
			
			}
	 }
}
 
	
   /* Loop through array and add up the total value
	* Add quantity on hand and multiply by its price
	* Add the value to a running total
	*/
 
	public double getTotalInvValue(){
		double sumOfInventory = 0.0;
		
		for (Product item : items) {
		   
			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}
	
	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");
		
		boolean hasItems = false;
		
		for (Product item : items) {
			if (item!= null)  {
				hasItems = true; 
				  System.out.println("Inventory is currently empty.\n"); }
		}
	}
}   
	   
			


 * @author Tammy
 */
class Product {
	
	private String name;
	private int quantity;
	private double price;
	private int productid = 0;
	
	// Set the default state of object
	
	public Product() {
		this (0,"Unknown", 0, 0.00);
	}
	
	// Constructor to specify name, quantity, and price for items
	public Product (int productId, String itemname, int quantityOnHand, double itemprice) {
		productid = productId;
		setName (itemname);
		setQuantityOnHand (quantityOnHand);
		setPrice (itemprice);
		
	}
	public void setName(String itemname) {
		name = itemname;
		}
	
	// Sets quantity on hand and defaults to zero, if negative
	public void setQuantityOnHand (int quantityOnHand) {
		if (quantityOnHand > 0) {
			quantity = quantityOnHand;
			}
		else { quantity = 0; }
		
	}
	// Set price of product and default to zero if negative
	public void setPrice (double itemPrice) {
		if (itemPrice > 0.00) {
			price = itemPrice;
			}
		else { price = 0.00; }
		
	}
	
	// Get product name
	public String getName() {
		return name;
		}
	
	public int getQuantityOnHand() {
		return quantity;
		
	}
	
	public double getPrice() {
		return price;
	}
	
	// Calculate value of stock on this item
	public double getItemValue() {
		return (price * (double)quantity);
	}
	
	@Override
	public String toString() {
		return name + "-" + price;
	}
	
}
  






These are the errors that I am getting,

C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\Inventory.java:14: illegal forward reference
private Product items[] = new Product[InventorySize];
C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\mydvdsjava\MyDvds.java:27: cannot access mydvdsjava.DVD
bad class file: C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\build\classes\mydvdsjava\DVD.class
class file contains wrong class: mydvdsjava.dvd
Please remove or make sure it appears in the correct subdirectory of the classpath.
DVD dvd = new DVD(); //invokes constructor
2 errors
BUILD FAILED (total time: 1 second)


I do not know what I am doing wrong here.

Was This Post Helpful? 0
  • +
  • -

#9 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 03:40 PM

View Postjavagreenhorn, on 19 Jun, 2008 - 03:31 PM, said:

View Postjavagreenhorn, on 19 Jun, 2008 - 03:22 PM, said:

View Postjavagreenhorn, on 19 Jun, 2008 - 03:14 PM, said:

View Postrgfirefly24, on 19 Jun, 2008 - 02:58 PM, said:

ok here is your problem. Once i put all the brackets on their own line i saw it.

 * June 13, 2008
 */
public class MyDvds{
   
  
    //main method begins execution of Java application
    /**
     * @param args the command line arguments
     */
    
    public static void main(String[] args) {

        //create and initialize a DVD object
        DVD dvd = new DVD(); //invokes constructor
       
        //create Scanner to obtain input from command window
        Scanner input = new Scanner( System.in);
        
        System.out.print("Enter product name, item number, number of units in stock, and price of each unit"); 
        // prompt for user input
        
        String title = "get this from input";
        
        double stock = 0.0; 
        double price = 0.0; 
        double item = 0.0; 
        dvd = new DVD(title, price, stock, item);
        
        System.out.println(dvd);
        
        System.out.println("Title is: " + dvd.getTitle());
        System.out.println("The item number is: " + dvd.getDVDNumber());
        System.out.println("The number of units in stock is: " + dvd.getDVDStock());
        System.out.println("The price of each unit is: " + dvd.getDVDPrice());
        System.out.println("The value of inventory is: " + dvd.inventoryValue());
  
        } //end method main
        
} //end classMyDvds





public class Inventory 
{
    // Set up an array 0f Products
    int inventorySize = 30;
    private Product items[] = new Product[InventorySize];

    // Set formatter to format values into currency
    DecimalFormat formatter = new DecimalFormat("$###,###.00");
    private int InventorySize;
}//this is closing your class too early remove it :)/>
    // Add a product to array, adds to first empty slot found



once you fix that and place all the ending brackets you need on inventory.java you should do just fine





Thanks so much for your help! I have done what you suggested and this is where I stand right now. When I build I get two errors. Here is my code and errors.

 * June 13, 2008
 */
public class MyDvds{
   
  
	//main method begins execution of Java application
	/**
	 * @param args the command line arguments
	 */
	
	public static void main(String[] args) {

		//create and initialize a DVD object
		DVD dvd = new DVD(); //invokes constructor	  
	   //create Scanner to obtain input from command window
		Scanner input = new Scanner( System.in);
		
		System.out.print("Enter product name, item number, number of units in stock, and price of each unit"); 
		// prompt for user input
		
		String title = "get this from input";
		
		double stock = 0.0; 
		double price = 0.0; 
		double item = 0.0; 
		dvd = new DVD(title, price, stock, item);
		
		System.out.println(dvd);
		
		System.out.println("Title is: " + dvd.getTitle());
		System.out.println("The item number is: " + dvd.getDVDNumber());
		System.out.println("The number of units in stock is: " + dvd.getDVDStock());
		System.out.println("The price of each unit is: " + dvd.getDVDPrice());
		System.out.println("The value of inventory is: " + dvd.inventoryValue());
  
		} //end method main
		
} //end classMyDvds




/* 
 * 
 */
// Import class to format values into currency
	import java.text.DecimalFormat;
/** 
 * 
 * @author Tammy
 */

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];
	
	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;

	// Add a product to array, adds to first empty slot found
public void addProduct (Product Item) {
		Product item;

	 for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item;
				return;
			
			}
	 }
}
 
	
   /* Loop through array and add up the total value
	* Add quantity on hand and multiply by its price
	* Add the value to a running total
	*/
 
	public double getTotalInvValue(){
		double sumOfInventory = 0.0;
		
		for (Product item : items) {
		   
			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}
	
	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");
		
		boolean hasItems = false;
		
		for (Product item : items) {
			if (item!= null)  {
				hasItems = true; 
				  System.out.println("Inventory is currently empty.\n"); }
		}
	}
}   
	   
			


 * @author Tammy
 */
class Product {
	
	private String name;
	private int quantity;
	private double price;
	private int productid = 0;
	
	// Set the default state of object
	
	public Product() {
		this (0,"Unknown", 0, 0.00);
	}
	
	// Constructor to specify name, quantity, and price for items
	public Product (int productId, String itemname, int quantityOnHand, double itemprice) {
		productid = productId;
		setName (itemname);
		setQuantityOnHand (quantityOnHand);
		setPrice (itemprice);
		
	}
	public void setName(String itemname) {
		name = itemname;
		}
	
	// Sets quantity on hand and defaults to zero, if negative
	public void setQuantityOnHand (int quantityOnHand) {
		if (quantityOnHand > 0) {
			quantity = quantityOnHand;
			}
		else { quantity = 0; }
		
	}
	// Set price of product and default to zero if negative
	public void setPrice (double itemPrice) {
		if (itemPrice > 0.00) {
			price = itemPrice;
			}
		else { price = 0.00; }
		
	}
	
	// Get product name
	public String getName() {
		return name;
		}
	
	public int getQuantityOnHand() {
		return quantity;
		
	}
	
	public double getPrice() {
		return price;
	}
	
	// Calculate value of stock on this item
	public double getItemValue() {
		return (price * (double)quantity);
	}
	
	@Override
	public String toString() {
		return name + "-" + price;
	}
	
}
  






These are the errors that I am getting,

C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\Inventory.java:14: illegal forward reference
private Product items[] = new Product[InventorySize];
C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\mydvdsjava\MyDvds.java:27: cannot access mydvdsjava.DVD
bad class file: C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\build\classes\mydvdsjava\DVD.class
class file contains wrong class: mydvdsjava.dvd
Please remove or make sure it appears in the correct subdirectory of the classpath.
DVD dvd = new DVD(); //invokes constructor
2 errors
BUILD FAILED (total time: 1 second)


I do not know what I am doing wrong here. I am also getting a yellow warning triangle on the line with:

public void addProduct (Product item) {

It states "Exporting non-public type through public API"

Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,885
  • Joined: 06-March 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 03:56 PM

Start by indenting your code correctly
Then you'll see that you have 2 } missing at the end
One to finish your printInventory() method
One to finish your class Inventory definition

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];

	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;

	// Add a product to array, adds to first empty slot found
	public void addProduct (Product item){

		for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item;
				return;
			}
		}
	}

	/* Loop through array and add up the total value
	 * Add quantity on hand and multiply by its price
	 * Add the value to a running total
	 */

	public double getTotalInvValue(){
		double sumOfInventory = 0.0;

		for (Product item : items) {

			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}

	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");

		boolean hasItems = false;

		for (Product item : items) {
			if (item!= null) {
				hasItems = true;

				System.out.println("Inventory is currently empty.\n"); 
			}
		}




This post has been edited by pbl: 19 June 2008 - 03:57 PM

Was This Post Helpful? 1
  • +
  • -

#11 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 04:41 PM

View Postpbl, on 19 Jun, 2008 - 03:56 PM, said:

Start by indenting your code correctly
Then you'll see that you have 2 } missing at the end
One to finish your printInventory() method
One to finish your class Inventory definition

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];

	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;

	// Add a product to array, adds to first empty slot found
	public void addProduct (Product item){

		for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item;
				return;
			}
		}
	}

	/* Loop through array and add up the total value
	 * Add quantity on hand and multiply by its price
	 * Add the value to a running total
	 */

	public double getTotalInvValue(){
		double sumOfInventory = 0.0;

		for (Product item : items) {

			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}

	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");

		boolean hasItems = false;

		for (Product item : items) {
			if (item!= null) {
				hasItems = true;

				System.out.println("Inventory is currently empty.\n"); 
			}
		}




Was This Post Helpful? 0
  • +
  • -

#12 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 04:50 PM

View Postpbl, on 19 Jun, 2008 - 03:56 PM, said:

Start by indenting your code correctly
Then you'll see that you have 2 } missing at the end
One to finish your printInventory() method
One to finish your class Inventory definition

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];

	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;

	// Add a product to array, adds to first empty slot found
	public void addProduct (Product item){

		for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item;
				return;
			}
		}
	}

	/* Loop through array and add up the total value
	 * Add quantity on hand and multiply by its price
	 * Add the value to a running total
	 */

	public double getTotalInvValue(){
		double sumOfInventory = 0.0;

		for (Product item : items) {

			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}

	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");

		boolean hasItems = false;

		for (Product item : items) {
			if (item!= null) {
				hasItems = true;

				System.out.println("Inventory is currently empty.\n"); 
			}
		}







I have gone through the code again and I am back to the original error message:
C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\Inventory.java:62: '}' expected

1 error
BUILD FAILED (total time: 0 seconds)

I have noticed that I have an extra line of text in the code:
public void addProduct (Product Item) {
Product item;

If I remove Product item; I get a cannot find symbol error and a choice to create a field item, parameter item, or local variable item. This error in the form of a lightbulb is on the line that contains:

items [i] = item;

and still get yellow triangle next to:

public void addProduct (Product item) {
Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,885
  • Joined: 06-March 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 04:52 PM

View Postjavagreenhorn, on 19 Jun, 2008 - 04:41 PM, said:

View Postpbl, on 19 Jun, 2008 - 03:56 PM, said:

Start by indenting your code correctly
Then you'll see that you have 2 } missing at the end
One to finish your printInventory() method
One to finish your class Inventory definition

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];

	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;

	// Add a product to array, adds to first empty slot found
	public void addProduct (Product item){

		for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item;
				return;
			}
		}
	}

	/* Loop through array and add up the total value
	 * Add quantity on hand and multiply by its price
	 * Add the value to a running total
	 */

	public double getTotalInvValue(){
		double sumOfInventory = 0.0;

		for (Product item : items) {

			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}

	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");

		boolean hasItems = false;

		for (Product item : items) {
			if (item!= null) {
				hasItems = true;

				System.out.println("Inventory is currently empty.\n"); 
			}
		}




I guess you forgot to type your reply javagreenhorn
Was This Post Helpful? 1
  • +
  • -

#14 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 07:01 PM

I have gotten to this point in my code. I have taken care of the yellow triangle and brackets, now I have a different type of error in this code:


/* 
 * 
 */
// Import class to format values into currency
	import java.text.DecimalFormat;
/** 
 * 
 * @author Tammy
 */

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];

	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;

	// Add a product to array, adds to first empty slot found
	private void addProduct (Product Item) {
		Product item;
		
	 for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item; 
				return; 
			}
	 }
}
 
	/* Loop through array and add up the total value
	* Add quantity on hand and multiply by its price
	* Add the value to a running total
	*/
 
	public double getTotalInvValue(){
		double sumOfInventory = 0.0;
		
		for (Product item : items) {
		   
			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}
	
	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");
		
		boolean hasItems = false;
		
		for (Product item : items) {
			if (item!= null)  {
				hasItems = true; 
				  System.out.println("Inventory is currently empty.\n"); 
			}
		 }
	 }
}		
		
		   
			   
  


The error is as follows:

C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\MyDvds.java\src\Inventory.java:14: illegal forward reference
private Product items[] = new Product[InventorySize];
1 error
BUILD FAILED (total time: 1 second)


I have looked to see what an illegal forward reference is; I don't know what I am missing.
Would appreciate any help.
Was This Post Helpful? 0
  • +
  • -

#15 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,885
  • Joined: 06-March 08

Re: Inventory Program Part 2

Posted 19 June 2008 - 07:26 PM

	int inventorySize = 30;
	private Product items[] = new Product[InventorySize];

	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;



You declare

private Product items[] = new Product[InventorySize];

but InventorySize (with a capital I) is just declared/defined 4 lines later ... I guess you have problem with
InventorySize and inventorySize (capital I or not)
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2