Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a java program.create a class circle that represents a round moving dot.

ID: 3759475 • Letter: C

Question

create a java program.create a class circle that represents a round moving dot. A circle object needs to contain double variables to store the: current X location of the circles center,current Y location of the circles center,radius of the circl,direction of the circles movement in radians,speed of the circles movement. The circle class must contain a constructor circle(double x,double y, double radians) that initializes the circles center x,y,radius. The circle class must provide the following methods:

public double geyY()/*returns the y coordinate of the center of this circle*/

public double getX()/*returns the x coordinate of the center of this circle*/

public double getRadius()/*returns the radius of this circle*/

public double getDir()/*returns the direction of movement*/

public void setX(double horz)/*set the x coordinate*/

public void setY(double vert)/*set the y coordinate*/

public void setSpeed(double fast)/*set the speed of the circle*/

public void getSpeed()/*get the speed of the circle*/

public void setDir(double compass)/*set the direction of the circle in radians*/

public void move(double time)/*updates the x and y coordinates after the time*/

update the x coordinate to x+cos(direction)*speed*time

update the y coordinate to y+sin(direction)*speed*time

Explanation / Answer

class Block {

  int x; // X position

  int y; // Y position

  int xSpeed; // Speed in the X direction

  int ySpeed; // Speed in the Y direction

}

protected void paint(Graphics g) {

  // Paint with the background color

  g.setColor(background);

  g.fillRect(0, 0, width, height);

  // Draw all of the blocks

  g.setColor(foreground);

  synchronized (this) {

    for (int i = 0, count = blocks.length; i < count; i++) {

      g.fillRect(blocks[i].x, blocks[i].y, SIZE, SIZE);

    }

  }

}

/**

   In order to create movement, you need to start a timer that

   periodically calls a method that updates the coordinates of each

   block and then causes the Canvas to be painted again.

**/

public synchronized void moveAllBlocks( ) {

  // Update the positions and speeds of all of the blocks

  for (int i = 0, count = blocks.length; i < count; i++) {

    blocks[i].move( );

    // Request a repaint of the screen

    repaint( );

  }

}