Need help with drawing a house for AP Computer Science class

S

ShakeN'Bake

Here is some code I found:


import apcslib.*;

public class DrawHouse
{
public static void main(String[] args)
{

DrawingTool pencil;
SketchPad paper;

paper= new SketchPad(500, 500);
pencil= new DrawingTool(paper);

pencil.turnLeft(90);
pencil.forward(50);
pencil.turnLeft(90);
pencil.forward(150);
pencil.turnLeft(90);
pencil.forward(100);
pencil.turnLeft(90);
pencil.forward(150);
pencil.turnLeft(90);
pencil.forward(100);
pencil.turnLeft(90);
pencil.forward(150);
pencil.turnLeft(90);
pencil.forward(250);
pencil.turnLeft(90);
pencil.forward(300);
pencil.turnLeft(90);
pencil.forward(400);
pencil.turnLeft(90);
pencil.forward(300);
pencil.turnLeft(90);
pencil.forward(400);
pencil.turnLeft(90);
pencil.forward(300);
pencil.turnLeft(75.964);
pencil.forward(206.155);
pencil.turnLeft(28.032);
pencil.forward(206.155);



}
}

I don't understand why there are decimal points in the last, third to
last, and fourth to last answers. Can someone please explain them to
me??
 
S

ShakeN'Bake

Another thing. Can someone give me a brief tutorial on drawing simple
things like houses or hexagons and circles?? Thanks.
 
P

Patricia Shanahan

ShakeN'Bake said:
Here is some code I found: ....
I don't understand why there are decimal points in the last, third to
last, and fourth to last answers. Can someone please explain them to
me??

I'd look at it the other way round. Why do you feel there should not be
any decimal points?

For a problem like this, I'd get myself a large piece of paper, a
pencil, a ruler, and a protractor, and pretend to be the computer. Start
in the middle of the paper, and use a scale that will allow you to go a
few hundred units in any direction without reaching an edge.

Is apcslib a library you are allowed to use?

Patricia
 
O

Oliver Wong

[small portion of code unsnipped]
DrawingTool pencil;
SketchPad paper;

paper= new SketchPad(500, 500);
pencil= new DrawingTool(paper);

pencil.turnLeft(90);
pencil.forward(50);

[...]

pencil.turnLeft(75.964);
pencil.forward(206.155);
pencil.turnLeft(28.032);
pencil.forward(206.155);

[/small portion of code unsnipped]
Do you understand why there are decimals in the second to last statement
then? Can you explain what your theory is?
I'd look at it the other way round. Why do you feel there should not be
any decimal points?

For a problem like this, I'd get myself a large piece of paper, a
pencil, a ruler, and a protractor, and pretend to be the computer. Start
in the middle of the paper, and use a scale that will allow you to go a
few hundred units in any direction without reaching an edge.

Or perhaps get a piece of paper which is exactly 500 units wide and 500
units tall, and read the documentation to find out what happens when the
pencil leaves the edge of the paper (in case it does something non-obvious,
like wrap around on the other side)! Might be a good idea to find out what
the starting coordinate and facing of the pencil is too.

- Oliver
 
B

Bill Medland

ShakeN'Bake said:
Here is some code I found:


import apcslib.*;

public class DrawHouse
{
public static void main(String[] args)
{

DrawingTool pencil;
SketchPad paper;

paper= new SketchPad(500, 500);
pencil= new DrawingTool(paper);

pencil.turnLeft(90);
pencil.forward(50);
pencil.turnLeft(90);
pencil.forward(150);
pencil.turnLeft(90);
pencil.forward(100);
pencil.turnLeft(90);
pencil.forward(150);
pencil.turnLeft(90);
pencil.forward(100);
pencil.turnLeft(90);
pencil.forward(150);
pencil.turnLeft(90);
pencil.forward(250);
pencil.turnLeft(90);
pencil.forward(300);
pencil.turnLeft(90);
pencil.forward(400);
pencil.turnLeft(90);
pencil.forward(300);
pencil.turnLeft(90);
pencil.forward(400);
pencil.turnLeft(90);
pencil.forward(300);
pencil.turnLeft(75.964);
pencil.forward(206.155);
pencil.turnLeft(28.032);
pencil.forward(206.155);



}
}

I don't understand why there are decimal points in the last, third to
last, and fourth to last answers. Can someone please explain them to
me??
(Are you sure the last but one wasn't 28.072?)

Because the author wanted the roof to be 50 units tall
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,045
Members
48,769
Latest member
Clifft

Latest Threads

Top