DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    15

    problem, maybe too many variables?

    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?

  2. #2
    Join Date
    Oct 2005
    Posts
    8
    You never set the variables you declare.

    int mynumsides*A*;
    double myangle = ((mynumsides - 2) * 180.0) / mynumsides;

    makePolygon(int mynumsides*B*, double sidelength)
    {


    }

    leaves mynumSides 0, no matter what you do, because mynumsides*A* and *B* are not the same thing.

    Do it like this instead:


    makePolygon(int mynumsidesB, double sidelength)
    {
    mynumsides=mynumsidesB;
    myangle = ((mynumsides - 2) * 180.0) / mynumsides;
    }

  3. #3
    Join Date
    Sep 2005
    Posts
    15
    thanks man, though it didn't help...

Similar Threads

  1. Reliability Problem
    By elise in forum Java
    Replies: 0
    Last Post: 10-30-2002, 04:40 AM
  2. Problem with Session variables and Cookies
    By Bragi Fannar in forum ASP.NET
    Replies: 0
    Last Post: 02-20-2002, 08:28 AM
  3. Replies: 0
    Last Post: 06-15-2001, 11:27 AM
  4. Replies: 0
    Last Post: 06-14-2001, 06:16 PM
  5. Replies: 0
    Last Post: 06-23-2000, 02:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links