public class InventoryPart2
{
public static void main( String[] args)
{
// create array of inventory of items
Product Items[] = new Product[3]; //Initializing the array
Items[0] = new Product(1,"pencils",100,0.5);
Items[1] = new Product(2,"notepads",200,2);
Items[2] = new Product(3,"printers",150,1);
}
private static void SortProductArray() // method for bubble sort
{
int flag = 0; //create a value to use as an indicator for sort
Product temp; //create a temporary object for sort
//Enter a while loop to sort the array
while(flag == 0)
{
flag = 1;
//enter a loop through the product array for sorting
for(int x = 0; x < Items.length - 1; ++x)
{
//See if this value is greater than the next
if(Items[x].name.comparteTo(Items[x+1].name) > 0)
{
//Switch this item and the next
temp = Items[x];
Items[x] = Items[x+1];
Items[x+1] = temp;
//reset the flag to 0
flag = 0;
}//end if
}//end for loop
}//end while loop
}//end sort method
public static void displayProduct(Product items[])
{
//Display the inventories one at a time using a for loop
for (int i=0;i<items.length;i++)
{
items[i].showInventory();
}
}
} //end
//Robert Turner. Product class for inventory program.
public class Product {
private int itemNum;
private String name = new String();
private int units;
private double price;
//sets and gets
public int getItemNum()
{
return itemNum;
}
public void setItemNum(int itemNum)
{
this.itemNum = itemNum;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getUnits()
{
return units;
}
public void setUnits(int units)
{
this.units = units;
}
public double getPrice()
{
return price;
}
public void setPrice(double price)
{
this.price = price;
}
//Constructor that takes arguments
Product(int _itemNum, String _name, int _units, double _price){ //Constructor
itemNum = _itemNum;
name = _name;
units = _units;
price = _price;
}
//Computes value of inventory
public double valueOfInventory()
{
return price * units;
}
//displays the details of the inventory
public void showInventory(){
System.out.println("Product Name : "+name);
System.out.println("Item Number : "+itemNum);
System.out.println("Number of Units: "+units);
System.out.println("Unit Price $"+price);
//call the valueOfInventory() method and display the value
System.out.println("The value of the inventory of "+name+ " is = "+valueOfInventory());
}
public int compareTo(Product o) {
int EQUAL = 0;
int comparison = this.name.compareTo(o.name);
if ( comparison != EQUAL )
return comparison;
return 0;
}
}
error states:
cannot find symbol
symbol : variable items
location: class InventoryPart2
for (int x =0;x < Items.length - 1; ++x)
^
what am I missing?

New Topic/Question
Reply




MultiQuote




|