• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java help..

jai6638

Golden Member
Hey.. am in a Intro to Programming class and the following is my assignment:

1. Using the Turtle Graphics Java Package create a smile face or pumpkin face.

2. This face must have the following:
a. The head must be round. See the code below to get a circle.
b. You must use the 6 Turtle Graphics Pen Messages that can be found on the handout on my website.
c. The eyes, nose and mouth must be at least 3 sides and implemented by a loop. (repetition structure)
d. Half circle for mouth
(Hint: the for loop that only loops 3 times for each eye)
e. Draw a flow chart of your program using the correct symbols and logic.
f. Submit a copy of your source code and flowchart.
______________________________________________________________


THe following is my source code

import TurtleGraphics.*;
class face
{
public static void main(String[] args)
{
// create a pen object
SketchPadWindow pad = new SketchPadWindow(600, 600);
Pen pen = new StandardPen(pad);

// declare a variable for drawing circle
int i;

// Draw Circle for face
pen.home();
pen.setDirection(90);
pen.down();
for(i=0; i<=120; i++)
{
double side = 2.0*3.14*50.0/120.0;
pen.move(side);
pen.turn(3);
}

//draw second eye ( eye on the right )

pen.up();
pen.home();
pen.turn(90);
pen.up();
pen.move(16);
pen.down();
pen.move(20);
pen.turn(-140);
pen.move(15);
pen.turn(-90);
pen.move(12);

//draw first eye ( eye on the left )

pen.turn(-128);
pen.up();
pen.move(40);
pen.down();
pen.move(16);
pen.turn(-140);
pen.move(16);
pen.turn(-100);
pen.move(14);

//draw nose

pen.up();
pen.move(10);
pen.down();
pen.move(10);
pen.turn(-125);
pen.move(10);
pen.turn(-135);
pen.move(10);

//draw mouth

pen.up();
pen.turn(-150);
pen.move(20);
pen.down();

int r;
for(i=0; i<=120; i++)

{
double side = 2.0*3.14*3.0/120.0;
pen.move(side);
pen.turn(3);
};
}

}

The problem is that i need to loop the eyes and nose ( as requested by my teacher in point C ) so as to prevent the use of Pen commands again and again... how do i do this?


thanks much ..
 
For a three-sided shape, you should probably loop three times (assuming each side is the same length). Write out the steps then translate to code:

1. Orient yourself facing east.
2. Move x number of steps.
3. Turn 135 degrees.
4. Repeat steps 2 and 3 twice.

You should now have an equilateral triangle.
 
how do u loop though?? With what you typed above, i would have to retype this two or three times right which woudnt be a loop since im physically typing it...

thanks
 
well this is the my first week of class.. the text book does explain loop statements in general but dunno how to apply it in this case!
 
Originally posted by: notfred
What kind of class has you doing graphical ANYTHING without understanding the basics of loops?

Well, it seems the teachers are in love with these graphical classes where they use the class to teacher you the basics, not the teacher. I think it's a stupid idea, but then again that's just me.

What happened to the good old print out the variables method?
 
Originally posted by: amdfanboy
Originally posted by: notfred
What kind of class has you doing graphical ANYTHING without understanding the basics of loops?

Well, it seems the teachers are in love with these graphical classes where they use the class to teacher you the basics, not the teacher. I think it's a stupid idea, but then again that's just me.

What happened to the good old print out the variables method?
Someone had the bright idea that the students will be more interested if they can "see" the results in pretty colors, than just if they create a program that says "the answer is 5."
 
Originally posted by: amdfanboy
Originally posted by: notfred
What kind of class has you doing graphical ANYTHING without understanding the basics of loops?

Well, it seems the teachers are in love with these graphical classes where they use the class to teacher you the basics, not the teacher. I think it's a stupid idea, but then again that's just me.

What happened to the good old print out the variables method?

To the teacher's credit, the graphics library seems pretty basic and easy-to-use. The focus of this program is obviously the control structure practice and not the GUI development.
 
Seems pretty similar to the old LOGO language that kids used to use to draw shapes on screen.

This sort of thing has been taught for 20 or more years.
 
Originally posted by: Kilrsat
Originally posted by: amdfanboy
Originally posted by: notfred
What kind of class has you doing graphical ANYTHING without understanding the basics of loops?

Well, it seems the teachers are in love with these graphical classes where they use the class to teacher you the basics, not the teacher. I think it's a stupid idea, but then again that's just me.

What happened to the good old print out the variables method?
Someone had the bright idea that the students will be more interested if they can "see" the results in pretty colors, than just if they create a program that says "the answer is 5."

Maybe I'm weird, but I find it more confusing.
 
Back
Top