Results 1 to 2 of 2

Thread: Help with print function

  1. #1
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with print function

    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)

    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:

    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);
        }
    Any help would be much appreciated.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's not all the code at all, since you haven't given the implementation of Product.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •