This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Ok , I'm really struggling with this... this is the Shape class inheritance hierarchy I have to stick too. Am I on the right tracks or not I do not know?
I was unsure how to include twodimensionshape for is there any point? The instructions here state I only need to concentrate on two dimensional shapes so I won't even need a Threedimensionalshape class? INSTRUCTIONS ======================================================================== a. Limit yourself to two dimensional shapes such as squares, rectangles, triangles and circles. b. Interaction with the user must be demonstrated. c. Let the user specify the position, size and shape to be used in drawing each shape. d. The user can specify many items of the same shape. e. As you create each shape, place a Shape reference to each new shape object into an array. f. Each class has its own draw method. Write a polymorphic screen manager that walks through the array sending draw messages to each object in the array to form a screen image. g. Redraw the screen image each time the user specifies an additional shape. Investigate the methods of class Graphics to help draw each shape. ================================================================ Here is the java code I got for each java file. Showshapes class - interaction with the user
Poly class [ edited to improve code layout, making it narrower -ds ] [ January 05, 2004: Message edited by: Dirk Schreckmann ]
If you haven�t looked at the Campfire Story How my Dog learned Polymorphism, be sure to take a look at it. It�s a nice (and funny) introduction to Polymorphism. Also check out the book "Head First Java" (see this thread) � it is an excellent book for learning Java an OOP. Looking briefly at your class hierarchy, I would say you are on the right track. Even if you only need to include 2D shapes, I would include the TwoDimensionalShape Class like you have. It will allow you to add 3D shapes in the future (and even 5D shapes once we get that pesky Space-Time continuum thing figured out). Others may have some suggestions for you... I don�t do much with Swing or AWT, so I�ll leave the specifics of your code to others as well.