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:
Code:public void printInventoryExceptions(int quantity)
Here is the full code I have so far for the application:Quote:
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.
Any help would be much appreciated.Code: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);
}
