File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Need help with code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help with code" Watch "Need help with code" New topic
Author

Need help with code

Taiwo Sokunbi
Greenhorn

Joined: Feb 01, 2012
Posts: 9
Task : Write a GraphicsProgram subclass that draws a pyramid consisting of bricks arranged in horizontal rows, so that the number of bricks in each row decreases by one as you move up the pyramid.

But all I have been able to generate is right angled pyramid.
Below is the code I wrote.
Any help will be greatly appreciated.




Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2301
    
  49
It's hard to understand your code as I have no idea what the GCompound class is. Also please don't use all upper case letters for variables, they are only for constants ie those declared as final static.

If you are successfully generating a right angle triangle then your problem is when you draw the next row your offset is wrong. You need to offset each new rows start position by half the width of a single brick. This is because each row has one less brick than the row below it, so to centre a row relative to the previous one you need to take off half a brick width at each end .
Taiwo Sokunbi
Greenhorn

Joined: Feb 01, 2012
Posts: 9
Thanks for the suggestion will try to do that.

The GCompound is part of acm package that belongs to GObject .
Taiwo Sokunbi
Greenhorn

Joined: Feb 01, 2012
Posts: 9
Thanks a lot it worked
@Tony
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2301
    
  49
My pleasure
 
GeeCON Prague 2014
 
subject: Need help with code