#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Method not working


    I am using BluJ on a course in Java and have an assignment to do but I am having problem with the code.

    I am trying to move a circle referenced by the receiver's ball instance variable to the position specified by the arguments xPos and yPos.

    I have done this:

    /**
    * Move the circle referenced by the receiver's ball
    * instance to the position specified by the
    * arguments xPos and yPos
    */
    public void moveBallTo(int xPos, int yPos)
    {
    this.ball.setXPos(xPos);
    this.ball.setYPos(yPos);
    }

    However when it comes to testing, I get an error message. The test code is:

    Circle c = new Circle();
    BallCourt bc = new BallCourt(c);
    bc.moveBallTo(100,200);

    The error message is:

    Compilation failed (28/11/2013 17:39:29)
    Error: line 1 - cannot find symbol - method moveBallTo(int,int)

    the full code includes
    import ou.*; // imported to access the OUColour class
    import java.awt.*; // imported to access the Toolkit class

    THE CODE:

    public class BallCourt
    {
    /* Instance variables */
    private Circle ball;
    private int rightEdge;
    private int bottomEdge;
    private int centreX;
    private int centreY;

    /**
    * Constructor for objects of class BallCourt
    */
    public BallCourt(Circle aCircle)
    {
    super();
    this.ball = aCircle;
    this.ball.setDiameter(20);
    rightEdge = 250;
    bottomEdge = 350;
    centreX = rightEdge/2;
    centreY = bottomEdge/2;
    }

    /**
    * Returns the rightEdge of the Shapes window
    */
    public int getRightEdge()
    {
    return rightEdge;
    }

    /**
    * Returns the bottomEdge of the Shapes window
    */
    public int getBottomEdge()
    {
    return bottomEdge;
    }

    /**
    * Returns the centreX of the Shapes window
    */
    public int getCentreX()
    {
    return centreX;
    }

    /**
    * Returns the centreY of the Shapes window
    */
    public int getCentreY()
    {
    return centreY;
    }

    /**
    * Sets the colour of the receiver's ball instance variable
    * to the value of the argument aColour.
    */
    public void setBallColour (OUColour aColour)
    {
    this.ball.setColour(aColour);
    }

    /**
    * Returns the colour of the receiver's ball instance variable.
    */
    public OUColour getBallColour ()
    {
    return this.ball.getColour();
    }

    /**
    * Sets the horizontal position of the receiver's ball instance
    * variable to the value of the argument x.
    */
    public void setBallXPos(int x)
    {
    this.ball.setXPos(x);
    }

    /**
    * Returns the horizontal position of the receiver's
    * ball instance variable.
    */
    public int getBallXPos()
    {
    return this.ball.getXPos();
    }

    /**
    * Sets the vertical position of the receiver's ball
    * instance variable to the value of the argument y.
    */
    public void setBallYPos(int y)
    {
    this.ball.setYPos(y);
    }

    /**
    * Returns the vertical position of the receiver's ball
    * instance variable.
    */
    public int getBallYPos()
    {
    return this.ball.getYPos();
    }

    /**
    * Causes execution to suspend for time number of milliseconds
    */
    public void delay(int time)
    {
    try
    {
    Thread.sleep(time);
    }
    catch (Exception e)
    {
    System.out.println(e);
    }
    }

    /**
    * Move the circle referenced by the receiver's ball
    * instance to the position specified by the
    * arguments xPos and yPos
    */
    public void moveBallTo(int xPos, int yPos)
    {
    this.ball.setXPos(xPos);
    this.ball.setYPos(yPos);
    }

    }

    I can't see what's wrong. Any ideas.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Please edit the post and wrap the code in code tags:

    [code]
    The code here
    [/code]

    Also the code needs a main() method so it can be executed for testing

IMN logo majestic logo threadwatch logo seochat tools logo