• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Polymorphism 2!?!!??!

Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
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

Square class

Shape class

Poly class
[ edited to improve code layout, making it narrower -ds ]
[ January 05, 2004: Message edited by: Dirk Schreckmann ]
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just completed a similar class hierarchy. Is there any reason you chose an interface over just abstract classes? Was that part of your instruction or did you make that decision, and if so - why?
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic