I am pretty new to Java and have a question about where to begin with my program.
The assignment is to 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.
Here is my code
I am really struggling where to start.
On the array side, would I use the array only to store the item name, or would the array need to include the other features?
I am confused since an array can only hold the same data type and don't think that the assignment is asking me to use multiple arrays.
Thanks for any pointers.
The assignment is to 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.
Here is my code
Code:
/**
*@author Greg Hamilton
*Program was changed 31 Aug 07
*The purpose of this program is to create a product class that holds an item number, name of the DVD movie, number of units in stock
*and the price of each unit
*/
public class Dvd
{
private String dvdTittle;
private double dvdStock;
private double dvdPrice;
private double dvdItem;
public Dvd( String tittle, double stock, double price, double item )
{
//implicit call to Object constructor occurs here
dvdTittle = tittle;
dvdStock = stock;
dvdPrice = price;
dvdItem = item;
} //end four-argument constructor
//set DVD name
public void setdvdTittle( String tittle )
{
dvdTittle = tittle;
} //end method setDvdTittle
//return dvd Tittle
public String getDvdTittle()
{
return dvdTittle;
} //end method getDvdTittle
//set Dvd stock
public void setDvdStock( double stock)
{
dvdStock = ( stock < 0.0 ) ? 0.0 : stock;
} //end method setDvdStock
//return dvd stock
public double getDvdStock()
{
return dvdStock;
} //end method getDvdStock
public void setDvdPrice( double price )
{
dvdPrice = ( price <0.0 ) ? 0.0 : price;
} //end method SetDvdPrice
//return dvd price
public double getDvdPrice()
{
return dvdPrice;
} //end method get Dvd Price
public void setDvdItem( double item )
{
dvdItem = ( item <0.0) ? 0.0 : item;
} //end method set dvd Item
//return dvd item
public double getDvdItem()
{
return dvdItem;
} //end method getDvdItem
// calculate inventory value
public double value()
{
return dvdPrice * dvdStock;
} //end method value
public static void main( String args[] )
{
//instantiate Collection object
Dvd aDvd= new Dvd ("Dejavu", 10, 12.50, 101);
System.out.println("Product Tittle is "+ aDvd.getDvdTittle() ); //display tittle
System.out.println("The number of units in stock is "+
aDvd.getDvdStock() ); //display units in stock
System.out.println("The price of each DVD is $"+ aDvd.getDvdPrice() ); //display price
System.out.println( "The item number is "+ aDvd.getDvdItem()); //display unit number
System.out.println( "The value of the inventory is $"+ aDvd.value() ); //display total value
} //end main
} //end class Dvd
On the array side, would I use the array only to store the item name, or would the array need to include the other features?
I am confused since an array can only hold the same data type and don't think that the assignment is asking me to use multiple arrays.
Thanks for any pointers.
Comment