Hello,

I need to write a program that holds a multiple product inventory. Using an array to store the items. The output should display the product info, one at a time. In addition, I have to include the Total Value of the entire inventory.

My only problem is, the total value of the entire inventory is not coming up.

I really appreciate any help...

Here is the code:

public class InventoryPart2 {

public static void main(String args []) {

DVD myDvd;


myDvd = new DVD(10001, "The Ring", 6, 15.95);
System.out.println(myDvd);

myDvd = new DVD(10002, "X-Men", 7, 17.99);
System.out.println(myDvd);

myDvd = new DVD(10003, "Italian Job", 5, 19.95);
System.out.println(myDvd);

myDvd = new DVD(10004, "Dodge Ball", 8, 16.95);
System.out.println(myDvd);

} //end main

} // end class InventoryPart2


class DVD {
private int itemNum;
private String dvdTitle;
private int dvdStock;
private double dvdPrice;

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

// set DVD Item
public void setItemNum(int item) {
itemNum = item;
} //end method set Dvd Item

//return DVD Item
public int getItemNum() {
return itemNum;
} //end method get Dvd Item

//set DVD Title
public void setDvdTitle(String title) {
dvdTitle = title;
} //end method set Dvd Title

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

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

//return dvd Stock
public int getDvdStock() {
return dvdStock;
} //end method get Dvd Stock

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

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

//calculate inventory value
public double value() {
return dvdPrice * dvdStock;
} //end method value

public String toString() {

return String.format("Item No: %3d Title: %-12s Quantity: %d Price: $%.2f Value: $%.2f",
itemNum, dvdTitle, dvdStock, dvdPrice, value());
	}

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(1, "There's Something About Mary", 12, 21.95));
		// Print out the inventory total value
		System.out.println("Total value of inventory is: " + myInventory.getInventoryValue());
		return myInventory.getInventoryValue();
	}
}

}

Hi,

Can you please tell me show how I would do it? I am new to java and the code that I wrote is from few different samples in the book.

Also, I need to sort the names... I don't know where insert this..

Arrays.sort(dvdTitle);

Thank you so much for your help!

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