[Bluej-discuss] Ex.4.38
Davin McCall
davmac at bluej.org
Wed Nov 15 04:21:08 GMT 2006
Hi Mike,
Think about this: how many times does the body of the "while" loop get
executed? (here's a hint: It will be executed while the condition
"it.hasNext()" is true. If the stock list is initially empty, how many
times will that be?)
Davin
Mike Stevens wrote:
>
> Hi Colleen, I'm not getting it, am I using the right loop here? I've
> tried a for each loop also and have had no success. I seems like when
> it hits my if loop it just pass's it on by and does nothing. I looked
> at the rest of the exercises and have tried everything I can think of
> and it just won't add item in. I did create another method to add in
> just to test and the else worked System.out.print("Id used");
>
> Any help would be great.
>
>
>
> public void addProduct(Product item)
>
> {
>
>
>
> Iterator it = stock.iterator();
>
> while(it.hasNext()) {
>
> Product inStock = (Product) it.next();
>
> if(inStock.getID() != item.getID())
>
> {
>
> stock.add(item);
>
> }else{
>
> System.out.print("Id used");
>
> }
>
> }
>
> }
>
>
>
>
>
>
>
>
>
> Thanks
>
> Mike
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> mailing list bluej-discuss at bluej.org
> To unsubscribe or change your preferences, go to
> http://lists.bluej.org/mailman/listinfo/bluej-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bluej.org/pipermail/bluej-discuss/attachments/20061115/e130c615/attachment.html
More information about the bluej-discuss
mailing list