Modify the test client in Turtle to produce stars with N points for odd N. Here
ID: 645596 • Letter: M
Question
Modify the test client in Turtle to produce stars with N points for odd N. Here is an example of someone doing to the same problem, I just do not understand how they got it to work: http://www.chegg.com/homework-help/questions-and-answers/public-class-turtle-private-double-x-y-private-double-angle-public-turtle-double-x0-double-q4568996 This will need to draw the star using StdDraw, not print an * to the output. I've had a lot of trouble with this program. Thanks in advance for all your help!
Here is Turtle:
public class Turtle
{
private double x, y;
private double angle;
public Turtle (double x0, double y0, double a0)
{
x = x0;
y = y0;
angle = a0;
}
public void turnLeft(double delta)
{
angle += delta;
}
public void goForward(double step)
{
double oldx = x, oldy = y;
x += step * Math.cos(Math.toRadians(angle));
y += step * Math.sin(Math.toRadians(angle));
StdDraw.line(oldx, oldy, x, y);
}
public static void main(String[] args)
{
int N = Integer.parseInt(args[0]);
double angle = 360.0 / N;
double step = Math.sin(Math.toRadians(angle/2));
Turtle turtle = new Turtle(.5, .0, angle/2);
for (int i = 0; i < N; i++)
{
turtle.goForward(step);
turtle.turnLeft(angle);
}
}
}
Explanation / Answer
This will helps you forget about above code..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.