[Bluej-discuss] Excercise 4.25 review please

JD dnaltrop at gmail.com
Sun Jun 18 18:36:41 BST 2006


Hi all!

Please review and comment on my solution for Exercise 4.24.  I have a
question at the bottom of this email as well.

Auction Class:

     /**
     * Close Lot
     * @return Close lots
     */

    public void closeAuction()
    {
        Iterator it = lots.iterator();
        while(it.hasNext()) {
            Lot lot = (Lot) it.next();
            System.out.println(lot.closeLot());
        }
    }


Lot Class:

    /**
     * @return A string representation of this lot's details.
     */
    public String closeLot()
    {
        String details = number + ": " + description;
        if(highestBid != null) {
            details += " sold for $" + highestBid.getValue() + "  to: "  +
highestBid.getBidder().getName();
        }
        else {
            details += "    (No bid)";
        }
        return details;
    }


Output:

1: Car sold for $3432  to: Carl

2: Cat    (No bid)


Question:

The following line of code gave me the most grief until I got it working.

highestBid.getBidder().getName();

It is an object reference to a method to another object to a method within
the object referenced by the getBidder() method!?!?!?  It works.  But what
the heck did I create here?  What is it called?  Have we covered this type
of construction in the book yet and I missed it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bluej.org/pipermail/bluej-discuss/attachments/20060618/11bceee1/attachment.html


More information about the bluej-discuss mailing list