PDA

View Full Version : Help with print function



trojansc82
10-25-2008, 08:17 PM
I need to print all of the products from a stock manager application with stock levels below a given value. This is the signature I've been given:



public void printInventoryExceptions(int quantity)


Note: Not all products should be displayed, only products that are equal or below the quantity specified. Print page headings even if there are no inventory exceptions.Here is the full code I have so far for the application:


public class StockManager
{
private Product[] stock;



public StockManager(int maxID)
{
stock = new Product[maxID];
}



public Product findProduct(int id)
{
return(stock[id]);
}

public Product findProduct(String name)
{
int maxID = stock.length;
boolean notFound = true;
Product temp = null;
for (int i = 0; i < maxID && notFound; i++) {
if ((stock[i] != null) && (stock[i].getName() == name)) {
notFound = false;
temp = stock[i];
}
}
return(temp);
}



public int numberInStock(int id)
{
int quantity = 0;
if (stock[id] != null) {
quantity = stock[id].getQuantity();
}
return(quantity);
}


public void printProductDetails()
{
for (int i=0; i < stock.length; i++) {
if (stock[i] != null) {
System.out.println(stock[i]);
}
}
}



public void addProduct(Product item)
{
if (stock[item.getID()] == null){
stock[item.getID()] = item;
}
}


public void delivery(int id, int amount)
{
if (stock[id] != null) {
stock[id].increaseQuantity(amount);
}
}


public Product removeProduct(int id)
{
Product temp = stock[id];
stock[id] = null;
return(temp);
} Any help would be much appreciated.

Twey
10-26-2008, 12:53 AM
That's not all the code at all, since you haven't given the implementation of Product.