Program requirements are as follows:

Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, 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.

I can not understand why I am getting and error in the beginning where it says "Public Static ....." the program comes up with and error that causes the program to terminate.. What am I doing wrong? Can some one please help point me in the direction I need to go....Thank

public class InventoryProgram2
{

	public static void main(String args []);
	{

       DVD dvd;


        dvd = new DVD("A Haunting in Conneticut", 4, 19.99, 685);
        System.out.println(dvd);
        System.out.println("Product Title is " + dvd.getDvdTitle());
        System.out.println("The number of units in stock is" + dvd.getDvdStock());
        System.out.println("The price of each DVD is" + dvd.getDvdPrice());
        System.out.println("The item number is " + dvd.getDvdItem());
        System.out.println("The value of the inventory is" + dvd.value());


        dvd = new DVD ("The Rose", 8, 19.98, 565);
        System.out.println(dvd);
        System.out.println("Product Title is " + dvd.getDvdTitle());
        System.out.println("The number of units in stock is" + dvd.getDvdStock());
        System.out.println("The price of each DVD is" + dvd.getDvdPrice());
        System.out.println("The item number is " + dvd.getDvdItem());
        System.out.println("The value of the inventory is" + dvd.value());


        dvd = new DVD ("Goodfellas", 10, 19.99,785);
        System.out.println(dvd);
        System.out.println("Product Title is " + dvd.getDvdTitle());
        System.out.println("The number of units in stock is" + dvd.getDvdStock());
        System.out.println("The price of each DVD is" + dvd.getDvdPrice());
        System.out.println("The item number is " + dvd.getDvdItem());
        System.out.println("The value of the inventory is" + dvd.value());


        dvd = new DVD ("Twilight",8,18.56,578);
        System.out.println(dvd);

        System.out.println("Product Title is " + dvd.getDvdTitle());
        System.out.println("The number of units in stock is" + dvd.getDvdStock());
        System.out.println("The price of each DVD is" + dvd.getDvdPrice());
        System.out.println("The item number is " + dvd.getDvdItem());
        System.out.println("The value of the inventory is" + dvd.value());

    }//end class main


} // end class InventoryProgram2
class DVD {
    private String dvdTitle;
    private double dvdStock;
    private double dvdPrice;
    private double dvdItem;

    public DVD(String title, int stock, double price, double item) {
        dvdTitle = title;
        dvdStock = stock;
        dvdPrice = price;
        dvdItem  = item;
    } //end four-argument constructor


    public void setDvdTitle(String title) {
        dvdTitle = title;
    } //end method  setDvdTitle

    //return DVD Title
    public String getDvdTitle() {
        return dvdTitle;
    } //end method getDvdTitle

    //set DVD Stock
    public void setDvdStock(double stock) {
        dvdStock = stock;
    } //end method setDvdStock

    //return DvdStock
    public double getDvdStock() {
        return dvdStock;
    } //end method get Dvdstock

    public void setDvdPrice(double price) {
        dvdPrice = price;
    } //end method setDvdPrice

    //return dvdPrice
    public double getDvdPrice() {
        return dvdPrice;
    } //end method get Dvd Price

    public void setDvdItem(double item) {
        dvdItem = item;
    } //end method setdvdItem

    //return DVD item
    public double getDvdItem() {
        return dvdItem;
    } //end  method getDvdItem

    //calculate <strong class="highlight">inventory</strong> value
    public double value() {
        return dvdPrice * dvdStock;

    } //end method value

} //end class DVD
class Inventory {
	DVD movies[] = new DVD[100];

	// Add to inventory
	public void addToInventory(DVD movie) {
	}

	// Get inventory value
	public double getInventoryValue() {
		Inventory myInventory = new Inventory();
		myInventory.addToInventory(new DVD("Dawn of the Dead", 25, 14.95, 68));
		// Print out the inventory total value
		System.out.println("Total value of inventory is: " + myInventory.getInventoryValue());
		return myInventory.getInventoryValue();
	}
}

Edited 7 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

In the first line of your main class you have

public static void main(String args []);
{

This should read

public static void main(String[] args){

The main() method takes a String[]. By convention we name it "args".

Ok I fixed that, thank you very much, it compiled sucessfully but now I am getting an eception in the main thread that is causing the program to exit.

it says class not found but there is a class and I have the files that followed after the program compiled. And I am looking at the main thread and I fail to see an error. Can someone please help

Ok I fixed that, thank you very much, it compiled sucessfully but now I am getting an eception in the main thread that is causing the program to exit.

it says class not found but there is a class and I have the files that followed after the program compiled. And I am looking at the main thread and I fail to see an error. Can someone please help

How are you compiling the code - using a GUI editor or by terminal/javac?

If you're doing it by hand, you'll need to compile first DVD, then Inventory, and finally InventoryProgram2 (in that order). A decent editor (like NetBeans) will do this automatically.

Before you run the program, make sure the three files:
InventoryProgram2.class
Inventory.class
DVD.class
Are in the directory.

For the beginner, I recommend downloading NetBeans (http://netbeans.org/downloads/index.html) and creating a project. Copy your code into the project and run inside the editor. This will ensure all files are compiled and the class-path is correct. It will also catch simple syntax errors like you made above.

Edited 7 Years Ago by theshadow27: n/a

Ok here we go I restarted my code over.

I got my Camera class to compile and my InventoryProgram class to compile. I am just experiencing 3 errors in my Inventory class.

Here are the 3 errors:

C:\Users\aks\Documents\NetBeansProjects\InventoryProgram2\src\Inventory.java:12: cannot find symbol
symbol : class myCamera
location: class Inventory
myInventory.addToInventory(new myCamera("Sony", 0, 0, 0.0));
1 error

C:\Users\aks\Documents\NetBeansProjects\InventoryProgram2\nbproject\build-impl.xml:528: The following error occurred while executing this line:

C:\Users\aks\Documents\NetBeansProjects\InventoryProgram2\nbproject\build-impl.xml:261: Compile failed; see the compiler error output for details.

// Fig 2.4: InventoryProgram.java
// Inventory program stores and monitors camera inventory

public class Camera {
    private int Number;
    private double Price;
    private String Name;
    private double TotalValue;

    public Camera(String ItemName, int ItemNumber, int NumberofUnits, double UnitPrice, double Value) {
        this.ItemName = ItemName;
        this.ItemNumber = ItemNumber;
        this.NumberofUnits = NumberofUnits;
        this.UnitPrice = UnitPrice;
        this.Value = Value;
    }

    private String ItemName;
    private int ItemNumber;
    private int NumberofUnits;
    private double UnitPrice;
    private double Value;
   

    {

        ItemName = Name;
        ItemNumber = Number;
        NumberofUnits = Number;
        UnitPrice = Price;
        TotalValue = Value;

        } //end four-argument constructor

    Camera(String string, int i, int i0, double d) {
        throw new UnsupportedOperationException("Not yet implemented");
    }


    {
        ItemName = Name;
        ItemNumber = Number;
        NumberofUnits = Number;
        UnitPrice = Price;
        TotalValue = Value;
    } //end four-argument constructor

       // set Item Name
    public void setItemName(String Name) {
        ItemName = Name;
    } //end method  setItemName

    //return Item Name

    public String getItemName() {
        return ItemName;
    } //end method getItemName

    //set Item Number
    public void setItemNumber(int Number) {
        ItemNumber = Number;
    } //end method setItemNumber

    //return Item Number
    public double getItemNumber(int Number) {
        return ItemNumber;
    } //end method get ItemNumber

    // set Number of Units
    public void setNumberofUnits(int Number) {
        NumberofUnits = Number;
    } //end method setNumberofUnits

    //return Number of Units
    public double getNumberofUnits(int Number) {
        return NumberofUnits;
    } //end method get Number of Units

    public void setUnitPrice(double Price) {
        UnitPrice = Price;
    } //end method setUnitPrice

    //return Unit Price
    public double getUnitPrice(double Price) {
        return UnitPrice;
    } //end method getUnitPrice

    //calculate <strong class="highlight">inventory</strong> value
    public double TotalValue(double Value) {
        return NumberofUnits * UnitPrice;

} // camera inventory

} // end class InventoryPart2
class InventoryProgram2
{

   public static void main( String [] args)
   {
       Camera camera = null;
 
 Camera myCamera = new Camera("Sony", 0, 0, 0.0);
 System.out.println(camera);
 
    }
 private Camera myCamera = new Camera("Toshiba", 0, 0, 0.0);

    {
 Camera myCamera = new Camera("Phillips", 0, 0, 0.0);




   } // end class main

    private InventoryProgram2() {
    }

    /**
     * @return the myCamera
     */
    public Camera getMyCamera() {
        return myCamera;
    }

    /**
     * @param myCamera the myCamera to set
     */
    public void setMyCamera(Camera myCamera) {
        this.myCamera = myCamera;
    }


}//end class InventoryProgram2
public class Inventory {

  private Camera myCamera[] = new Camera[0];

  // Add to inventory
 public void addToInventory(Camera camera) {
     }
 // Get Inventory value
 public double getTotalValue() {
  Inventory myInventory = new Inventory();
  myInventory.addToInventory(new myCamera("Sony", 0, 0, 0.0));
  // Print out the inventory total value
  System.out.println("Total value of inventory is: " +
  myInventory.getTotalValue());
  return myInventory.getTotalValue();
 }

   
    }
This article has been dead for over six months. Start a new discussion instead.