[Bluej-discuss] Chapter 4 Exercise 4.33

Luis Moreira Luis.Moreira at jet.uk
Fri Jul 7 15:36:52 BST 2006


Hi Marie,

At first glance I can not see any reason for this not to work, the only
thing that will not work is the fact that you have a semi-colon before
the bracket on the if statement.

Best regards

                        Luis

 

public Product findProduct(int id)

    {

         Iterator it = stock.iterator();

         while(it.hasNext()){

         Product product = (Product)it.next();

         if(product.getID() == id);{

         return product;

     }

 }

          return null;

    }

 

 

 

Luis Moreira

luis.moreira at jet.uk

tel. 01235464615

JET PSU Department

UKAEA Culham Division

J20/1/55, Culham Science Centre

Abingdon

Oxfordshire

OX14 3DB

 

-----Original Message-----
From: bluej-discuss-bounces at bluej.org
[mailto:bluej-discuss-bounces at bluej.org] On Behalf Of Marie Buchan
Sent: 07 July 2006 15:08
To: bluej-discuss at bluej.org
Subject: [Bluej-discuss] Chapter 4 Exercise 4.33

 

Hi.

Can anyone see why this code does not find a product? If an invalid id
number is put in, the products which are there are returned instead of
null being returned. If a valid id is searched for, it returns all the
products.? Thanks again. 

Marie

 

public Product findProduct(int id)

    {

         Iterator it = stock.iterator();

         while(it.hasNext()){

         Product product = (Product)it.next();

         if(product.getID() == id);{

         return product;

     }

 }

          return null;

    }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bluej.org/pipermail/bluej-discuss/attachments/20060707/d48505d3/attachment.html


More information about the bluej-discuss mailing list