Also I do not understand why my program will not go through the entire array, it only displays the first line in the array. If someone could please tell me what I am doing wrong I would greatly appreciate it.
Thank you!
Here is my code...
//Inventory Program Part 1
//Inventory Class - product class that holds the item number, the name of the product, the number of
//units in stock, and the price of each unit.
public class Inventory
{
private double ItemNumber; //to store Item number
private String ItemName; //to store Item name
private double UnitsInStock; //to store number of units in stock
private double UnitPrice; //to store Unit price
//private double InventoryValue; //to store Inventory value
//private double TotalInventory; //to store Total Inventory value
public Inventory() //constructor with no initial variables
{
this ("", 0.0, 0.0, 0.0);
}
public Inventory (String name, double number, double stock, double price)
{
ItemName = name; //set Item name
ItemNumber = number; //set Item number
UnitsInStock = stock; //set Units in stock
UnitPrice = price; //set Unit price
}
//method to set the Item name
public void setItemName( String name )
{
ItemName = name; //store the Item name
} //end method setItemName
//method to get the Item name
public String getItemName()
{
return ItemName;
} //end method getItemName
//method to set the Item number
public void setItemNumber( int number )
{
ItemNumber = number; //store the Item number
} //end method setItemNumber
//method to get the Item number
public double getItemNumber()
{
return ItemNumber;
} //end method getItemNumber
//method to set the UnitsInStock
public void setUnitsInStock( double stock )
{
UnitsInStock = stock; //store the Units in stock
} //end method setUnitsInStock
//method to get the UnitsInStock
public double getUnitsInStock()
{
return UnitsInStock;
} //end getUnitsInStock
//method to set the UntiPrice
public void setUnitPrice( double price )
{
UnitPrice = price; //store the Unit price
} //end method setUnitPrice
//method to get the UnitPrice
public double getUnitPrice()
{
return UnitPrice;
} //end getUnitPrice
//method to set Inventory value
//public void setInventoryValue(double value)
//{
// InventoryValue = value;
//} //end method setInventoryValue
//method to get InventoryValue
//public double getInventoryValue()
//{
// return InventoryValue;
//} //end method to getInventoryValue
public double getInventoryValue()
{
return UnitPrice*UnitsInStock;
} //end method to getInventoryValue
//method to set TotalInventory
public void setTotalInventory(double value)
{
TotalInventory = total;
} //end method setTotalInventory
//method to get TotalInventoty
public double getTotalInventory()
{
return TotalInventory;
} //end method to getTotalInventory
} //end class Inventory
//Inventory Test program part 1
//InventoryTest class
import java.util.Arrays;
public class InventoryTest1
{
public static void main( String args[] )
{
// instantiate an Inventory object
Inventory myInventory = new Inventory();
//displays welcome message
System.out.println ("DVD Collection Inventory");
System.out.println();//skips a line
//create and initialize an array of DVDs
int Inventory DVDs = new Inventory[5];
DVDs[0] = new Inventory("The Day After Tomorrow", 112.1, 7, 12.99);
DVDs[1] = new Inventory("Dejavu", 114.1, 25, 14.99);
DVDs[2] = new Inventory("Live Free or Die Hard", 116.1, 15, 10.99);
DVDs[3] = new Inventory("Fantastic Four", 102.1, 10, 0.99);
DVDs[4] = new Inventory("The Island", 104.1, 5, 9.99);
//For each array element, output value
for (int count = 0; count < DVDs.length; count++ );
System.out.printf("Product Name: %s\n", DVDs[count].getItemName());
System.out.printf("Item Number: %4.2f\n", DVDs[count].getItemNumber());
System.out.printf("Units In Stock: %.2f\n", DVDs[count].getUnitsInStock());
System.out.printf("Unit Price: $%4.2f\n", DVDs[count].getUnitPrice());
System.out.printf("Inventory Value: $%4.2f\n", DVDs[count].getInventoryValue());
System.out.println(); //blank line to seperate products
}//end main
}//end class InventoryTest1

New Topic/Question
Reply




MultiQuote









|