java help

Discussion in 'OT Technology' started by Grifter, Mar 5, 2005.

  1. Grifter

    Grifter Silver Member

    Joined:
    Dec 21, 2000
    Messages:
    3,117
    Likes Received:
    0
    Location:
    the southwest
    copied straight form the text book

    javac Circle.java

    Circle.java:70: cannot resolve symbol
    symbol : variable PI
    location: class Math
    return Math.PI * getDiameter();
    ^
    Circle.java:76: cannot resolve symbol
    symbol : variable PI
    location: class Math
    return Math.PI * radius * radius;
    ^
    2 errors

    Code:
    // Fig. 9.6: Circle.java
    // Circle class contains x-y coordinate pair and radius
    
    public class Circle
    {
    	private int x;		// x-coordinate of Circle's center
    	private int y;		// y-coordinate of Circle's center
    	private double radius;	// Circle's radius
    
    	// no-argument constructor
    	public Circle()
    	{
    		// implicit call to Object constructor occurs here
    	}
    
    	// constructor
    	public Circle(int xValue, int yValue, double radiusValue)
    	{
    		// implicit call to Object constructor occurs here
    		x = xValue;	// no need for validation
    		y = yValue;	// no need for validation
    		setRadius(radiusValue);
    	}
    
    	// set x in coordinate pair
    	public void setX(int xValue)
    	{
    		x = xValue;	// no need for validation
    	}
    
    	// return x from coordinate pair
    	public int getX()
    	{
    		return x;
    	}
    
    	// set y in coordinate pair
    	public void setY(int yValue)
    	{
    		y = yValue;	// no need for validation
    	}
    
    	// return y from coordinate pair
    	public int getY()
    	{
    		return y;
    	}
    
    	// set radius
    	public void setRadius(double radiusValue)
    	{
    		radius = (radiusValue < 0.0 ? 0.0 : radiusValue);
    	}
    
    	// return radius
    	public double getRadius()
    	{
    		return radius;
    	}
    
    	// calculate and return diameter
    	public double getDiameter()
    	{
    		return 2 * radius;
    	}
    
    	// calculate and return circumference
    	public double getCircumference()
    	{
    		return Math.PI * getDiameter();
    	}
    
    	// calculate and return area
    	public double getArea()
    	{
    		return Math.PI * radius * radius;
    	}
    
    	// return String representation of Circle object
    	public String toString()
    	{
    		return "Center = [" + x + ", " + y + "]; Radius = " + radius;
    	}
    } // end class Circle
    im hearing that i need to import the Math class but the book says
     
  2. beez

    beez New Member

    Joined:
    Jun 3, 2004
    Messages:
    19,143
    Likes Received:
    0
    Location:
    Queens
    Have you tried importing it?
     
  3. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,922
    Likes Received:
    10
    Location:
    Los Angeles
    You still having a problem with that thing? :mamoru:
     
  4. Grifter

    Grifter Silver Member

    Joined:
    Dec 21, 2000
    Messages:
    3,117
    Likes Received:
    0
    Location:
    the southwest
    i tried it again
    Math is case sensitive :o

    the prof wasnt able to help me last week and i didnt touch it until today :hs:
     

Share This Page