ere's the problem. a school assignment(extra credit) but something goes horribly wrong. i do use a DrawSquare class, which enables you to draw using move, forward, and other such commands.
Code:public class makePolygon { double sidelength; int mynumsides; double myangle = ((mynumsides - 2) * 180.0) / mynumsides; double r; double R; double perim = (mynumsides * sidelength); makePolygon(int mynumsides, double sidelength) { } double Angle(int mynumsides) { return myangle; } double getArea() { return ((1/2) * r * (mynumsides * sidelength)); } double getSideLength(double sidelength) { return sidelength; } double getPerim(int mynumsides, double sidelength) { return (mynumsides * sidelength); } double calcNew(double sidelength) { return (Math.sqrt(4)); } } import apcslib.*; import chn.util.*; public class polygonMain { public static void main(String[] args) { double numlength; int numsides; double perim; double r; double R; double angle; int i; ConsoleIO console = new ConsoleIO(); System.out.print("Number of sides: "); numsides = console.readInt(); System.out.print("\nLength of a side: "); numlength = console.readDouble(); makePolygon makeit = new makePolygon(numsides, numlength); System.out.print("\nYour perimeter is: "); perim = makeit.getPerim(numsides,numlength); System.out.println(perim); System.out.print("\nr = "); r = console.readDouble(); int length = (int)numlength; angle = makeit.Angle(numsides); DrawingTool pen; SketchPad paper; paper = new SketchPad(length * 4, length * 4); pen = new DrawingTool(paper); pen.move(r); pen.down(); pen.turnLeft((angle + 90)); for ( i=1; i<numsides; i++ ) { pen.move(numlength); pen.turnLeft(angle); } } }
the output should be a regular polygon, though what happens is it moves to the point specified, then it puts the pen down(this enables it to start drawing). but instead of drawing a polygon, it draws a diagonal line that's who knows how long!! can anyone see something wrong with my code?


Reply With Quote


Bookmarks