hey guys
i'm hopeless with java can someone help me out ??
i am using three classes for my program
the following two and a ClientUI class
this is the menu in my client
- Add a new item to the collection
- Load some items into the collection
- Display list of items in the collection
- Find an item in the collection
- Display found items name
- Display 'value' of found item
- Sell an item
- Display item details
- Total value of stock items
- Display items to reorder
- Delete an item
- quit
i can't figure out how to do the stuff in bold.
everything else seems to work.
[SIZE=1]class Item
{
private String name;
private int quantity;
private double price;
double itemValue;
public Item(String n, int q, double p)
{
name = new String(n);
quantity = q;
price = p;
}
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;
}
[B]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 itemVal)
{
itemVal = quantity * price;
return itemVal;
}[/B]
public String toString(String n, int q, double p)
{
String a = "\nItem Name: " + getName() + "\nQuantity: " + getQuantity()+"\nPrice: " + getPrice() + "\n";
return a;
}
}[/SIZE]
[SIZE=1]class StockTake
{
private static int DEFAULTSIZE = 50;
private static int MAXITEMS;
private int length=0;
private Item[] it;
static String name;
static int quantity;
static double price;
static String itemName;
private void init()
{
it = new Item[MAXITEMS];
length = 0;
}
public StockTake()
{
MAXITEMS = 12;
init();
}
public StockTake( int length )
{
if( length <= 0 )
length = DEFAULTSIZE;
MAXITEMS = length;
init();
}
public boolean addItem(String n, int q, double p)
{
if (length == MAXITEMS)
{
return false;
}
else
{
it[length] = new Item(n, q, p);
length++;
return true;
}
}
public String findItem( String itemName )
{
int i = 0;
while( i < length )
{
if( it[i].getName().equals(itemName) )
itemName = it[i].getName();
i++;
return (itemName);
}
return null;
}
public boolean deleteItem(String itemName)
{
int i = 0;
int index = -1;
while( i < length )
{
if( it[i].getName().equals(itemName) )
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[i] == null)
{
it[i] = it[i+1];
it[i+1] = null;
}
}
}
public String toString()
{
String o = "";
for (int i=0; i < length; i++)
o += "\nItem Name: " + it[i].getName() + "\nQuantity: " +it[i].getQuantity()+"\nPrice: " + it[i].getPrice() + "\n";
return o;
}
public double foundItemVal(double itemVal)
{
{
int i = 0;
while( i < length )
{
if( it[i].getName().equals(itemName) )
return (itemVal);
i++;
}
return '0';
}
}
}[/SIZE]