• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with a simple pyrimid program  RSS feed

 
Mahesh Mire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was learning Java and there was this exersize to construct a simple pyramid of prespecified height and width. The program i wrote is turining up with the wrong result. Any help would be much apreciated.





 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the result and what's wrong with it?
 
Mahesh Mire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:What's the result and what's wrong with it?

There is a single rectangle in the applet window with 2 separate rectangles right at the top such that you can see only their bases.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like something's wrong with "y".

Are these statements doing what you want?

y=-BRICK_HEIGHT;
x=-(BRICK_WIDTH/2);
 
Mahesh Mire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Sounds like something's wrong with "y".

Are these statements doing what you want?

y=-BRICK_HEIGHT;
x=-(BRICK_WIDTH/2);


I difinitely use BRICK_HEIGHT. dont know why the underscore didnt get printed but i used the correct version.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Review where you use a = a - SOMETHING and where you use a = -SOMETHING, where "a" is any variable. Are the values really what you want?

Keep this in mind:

a = a - SOMETHING;

is the same as

a -= SOMETHING;

but not

a = -SOMETHING;
 
Mahesh Mire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Review where you use a = a - SOMETHING and where you use a = -SOMETHING, where "a" is any variable. Are the values really what you want?

Keep this in mind:

a = a - SOMETHING;

is the same as

a -= SOMETHING;

but not

a = -SOMETHING;



Yes. Got you.

But the program still doesnt work. Now there isnt a single rectangle on screen.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point I'd focus on getting one brick in the right place. Comment out the other code or start another program.

Then think about what is happening to x and y. x++ is to the right; x-- is to the left; y++ is up; y-- is down. Get two bricks in the right place, and so on.

Also, post your code.
 
Mahesh Mire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:At this point I'd focus on getting one brick in the right place. Comment out the other code or start another program.

Then think about what is happening to x and y. x++ is to the right; x-- is to the left; y++ is up; y-- is down. Get two bricks in the right place, and so on.

Also, post your code.

Got the program to work. Weirdly it wasnt on the screen even in fullscreen but i had to scroll right to the bottom of the window where the pyamid was.

Your help was much appreciated thanks.

on a related topic, while working on programming a microcontrller i could debug the program line by line. Is it possible in eclipse too? Where can i find information about that. Thanks again.
 
Mahesh Mire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is how do i debug the program line by line?
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Eclipse, look for the bug icon or next to Run as is a menu item Debug as. You have to set a break point but then you can step thru the program.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!