Lab 10 Pre-Lab Assignment     Name ____________________________________________

  1. A circle is defined in mathematics as the set of all points equidistant from a given point (called the center of the circle). Hence a circle is characterized by its center and its radius. Fill in the following to implement a class called Circle that has three pieces of instance data - the x coordinate of the center, the y coordinate of the center, and the radius.
    1. Fill in the declarations of the instance variables (assume all three are type int).
    2. Fill in the code for a constructor that takes 3 parameters for the x and y coordinates of the center of the circle and the radius of the circle and uses those to initialize the instance variables.
    3. Write an accessor method getRadius that returns the radius.
    4. Write code for a method named area that computes and returns the area of the circle. Note that the area of a circle is pi (use Math.PI) times the square of the radius - that will be type double so the return type for the method should be double. The method takes no parameters.
    5. Write a method named resize that takes one parameter of type int and changes the radius by that amount (adds the amount to the radius). The method should not return anything (this means the return type in the header is the reserved word void). NOTE: The parameter can be negative (this would make the circle smaller) - no change to the radius should be made if adding the parameter would result in a negative radius.
    6. Write a method named move that takes two parameters of type int - the first is the amount to change the x coordinate of the center (this gives the horizontal distance to "move" the circle) and the second is the amount to change the y coordinate of the center (the vertical distance to "move" the circle).
    7. Write a toString method that returns a string that includes the center and radius in a format similar to "Center at (5, 6); Radius 10"
      
      public class Circle
      {
          // Declare the instance data - be sure to use the appropriate visibility modifier
      
      
      
      
      
      
      
      
      
      
      
      
      
          // Constructor - takes three int parameters for the x and y coordinates
          // of the circle and the radius and uses them to initialize the circle. 
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
          // getRadius - returns the radius
      
      
      
      
      
      
      
      
      
      
      
          // area - computes and returns the area of the circle (type double)
      
      
      
      
      
      
      
      
      
      
      
          // resize - takes one parameter of type int representing the
          // amount to change the size of the radius; the radius is changed
          // by that amount
      
      
      
      
      
      
      
      
      
      
      
      
      
          // move - takes two parameters of type int representing the amount
          // to move the circle in the horizontal and vertical directions;
          // the center is moved by the amounts passed in.
      
      
      
      
      
      
      
      
      
      
      
      
          // toString - returns a string representation of the circle
      
      
      
      
      
      
      
      
      
      
      
      
      
      } 
      
      

  2. Fill in code in the following client program as instructed by the comments.
    
    public class CircleTest
    {
       // Use some methods in the Circle class to test them
       public static void main (String[] args)
       {
          // Declare and instantiate a Circle object with center at
          // the point (13, 4) and radius 20. (Name your object testCircle)
    
    
    
    
    
    
    
          // Write a statement that prints the area of the circle (invoke
          // the area method in your print statement)
    
    
    
    
    
    
    
          // Write a statement that increases the radius of testCircle by 5. 
    
    
    
    
    
    
    
          // Write a statement that prints the new radius of the circle
          // (invoke the getRadius method in your print statement).
    
    
    
    
    
    
    
    
          // Write a statement that moves the circle by adding -5 to the
          // x coordinate and 8 to the y coordinate.  Use the move method.
    
    
    
    
    
    
    
          // Write a statement that prints the testCircle object
    
    
    
    
    
    
       }
    }