Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 4
There are 1 users currently browsing forums.
Java Programming Created by Sun Microsystems, Java remains to be one of the most powerful, cross-platform languages of choice by professionals everywhere. Capable of creating advanced desktop applications and web services, Java is tough to master, so ask your questions here.

Reply
  #1  
Old 10-25-2008
Toddler
 
Join Date: Oct 2008
Posts: 16
Rep Power: 0
JohnDavis32 is on a distinguished road
Need to print all products from a Stock Manager

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) 
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.
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.
Reply With Quote
  #2  
Old 10-25-2008
Toddler
 
Join Date: Oct 2008
Posts: 16
Rep Power: 0
JohnDavis32 is on a distinguished road
Re: Need to print all products from a Stock Manager

I'm assing it's a loop I need to set up, so I have set something up similar to the one earlier in the code:

Code:
public void printInventoryExceptions(int quantity) 
   {
        for (int i=0; i < stock.length; i++) {
            if (stock[i] != null) {
                System.out.println(quantity);
            }
        }
    }
Reply With Quote
  #3  
Old 10-25-2008
Toddler
 
Join Date: Oct 2008
Posts: 16
Rep Power: 0
JohnDavis32 is on a distinguished road
Re: Need to print all products from a Stock Manager

Alright, now this is what I have, but nothing is printing:

Code:
public void printInventoryExceptions(int quantity) 
   {
        for (int i=0; i < stock.length; i++) {
            if (stock[i] != null) {
                System.out.println(stock[i].getQuantity());
            }
        }
    }
Unfortunately, I just found out that this has to do with an "exception report", but we haven't covered it in the BlueJ book yet and I have 9 hours left to figure this out.

Any help would be amazing.
Reply With Quote
  #4  
Old 10-25-2008
Toddler
 
Join Date: Oct 2008
Posts: 16
Rep Power: 0
JohnDavis32 is on a distinguished road
Re: Need to print all products from a Stock Manager

This is the newest code, and it does print something, just not what I need:

Code:
public void printInventoryExceptions(int quantity) 
   {
        int maxID = stock.length;
        boolean notFound = true;
        Product temp = null;
        for (int i = 0; i < maxID && notFound; i++) {
            if ((stock[i] != null)){
                notFound = false;
                temp = stock[i];
                quantity = temp.getQuantity();
            }
        }
        System.out.println("There are " + quantity + " " + " product ID " + stock.length );
    }
The code is now printing "There are 100 product ID 1", which is not what I need, but at least it's printing something. I need it to print anything less than 100 and the name of the product, but I don't know how to add the name of the product.
Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Reviews?] Written application Reaper General Programming 11 07-13-2007 07:32 PM
Instant Hacking (An Introduction to Python) Part 1 jacotyco Articles, Tutorials, and Guides 3 01-30-2007 10:35 AM
help with my code plz tony1 Visual Basic Programming 5 01-25-2007 08:35 AM