hi all,
just looking for some help with setting up an array of items for a stocktake program.
i have an item class that works, and now i need to create an array to hold an array of the items. the item class code is
class Item
{
private String name;
private int quantity;
private double price;
public Item()
{
String name = " ";
int quantity = 0;
double price = 0.0;
}
public Item(String name)
{
name = name;
}
public String getName()
{
return name;
}
public int getQuantity()
{
return quantity;
}
public double getPrice()
{
return price;
}
public void setName(String name)
{this.name = name;
}
public void setPrice(double price)
{
this.price = price;
}
public int sell(int sellQuant)
{
while (quantity>0)
{
quantity = quantity - sellQuant;
if (sellQuant > quantity)
System.out.print("Order exceeds stock limit.");
}
return quantity;
}
public int order(int newQuant)
{
quantity += newQuant;
return quantity;
}
public double value(double itemValue)
{
itemValue = quantity * price;
return itemValue;
}
public String toString()
{
return name + "\n" + quantity + "\n" + price;
}
}
i've started the stocktake class but i havn't gotten very far. so far i've got this
class StockTake
{
private static final int MAXSIZE = 10;
private int length=0;
private Item[] it;
static String item;
public StockTake()
{
it = new Item[MAXSIZE];
}
public boolean addItem(String Item)
{
if (length == MAXSIZE)
{
return false;
}
else
{
it[length] = new Item(item);
length++;
return true;
}
}
public boolean deleteItem(String item)
{
int i = 0;
int index = -1;
while( i < length )
{
if( it.getName().equals(item) )
index = i;
i++;
}
if (index >=0)
{
it[index] = null;
length--;
rePack();
return true;
}
else
return false;
}
private void rePack()
{
for (int i=0; i <length; i++)
{
if (it == null)
{
it = it[i+1];
it[i+1] = null;
}
}
}
public String findItem( String item )
{
int i = 0;
while( i < length )
{
if( it.getName().equals(item) )
return (it.getName() + " found\n");
i++;
}
return null;
}
}
can anyone tell me if any of this makes any sense????
cheers
syd