Question

In: Computer Science

Problem 3.2 (Please download Point.java to complete this problem) Every circle has a center and radius....

Problem 3.2 (Please download Point.java to complete this problem)

Every circle has a center and radius. Given the radius, we can determine the circle’s area and circumference. Given the center, we can determine its position in the x-y plane. The center of a circle is a point in the x-y plane. Please do the following:

  1. Design the child class Circle that can store the radius and the center of the circle based on the class Point we talked in the class. You should be able to perform the usual operation on a circle, such as setting radius, printing the radius, calculating and printing the area and circumference, and carrying out the usual operations on the center.
  2. Write a test program to test your program

Here is the Point.Java program:

// class Point

public class Point
{
        protected double x, y; // coordinates of the Point

                //Default constructor
        public Point()
        {
        setPoint( 0, 0 );
        }

                //Constructor with parameters
        public Point(double xValue, double yValue )
        {
        setPoint(xValue, yValue );
        }

                // set x and y coordinates of Point
        public void setPoint(double xValue, double yValue )
        {
        x = xValue;
        y = yValue;
        }

                // get x coordinate
        public double getX()
        {
        return x;
        }

                // get y coordinate
        public double getY()
        {
        return y;
        }

                // convert point into String representation
        public String toString()
        {
        return "[" + String.format("%.2f", x)
               + ", " + String.format("%.2f", y) + "]";
        }

     //Method to compare two points
        public boolean equals(Point otherPoint)
        {
        return(x == otherPoint.x &&
               y == otherPoint.y);
        }

     //Method to compare two points
        public void makeCopy(Point otherPoint)
        {
        x = otherPoint.x;
        y = otherPoint.y;
        }

        public Point getCopy()
        {
        Point temp = new Point();

        temp.x = x;
        temp.y = y;

        return temp;
        }

                // print method
        public void printPoint()
        {
        System.out.print("[" + String.format("%.2f", x)
                       + ", " + String.format("%.2f", y) + "]");
        }

}  // end class Point

Solutions

Expert Solution

// class Point

class Point
{
protected double x, y; // coordinates of the Point

//Default constructor
public Point()
{
setPoint( 0, 0 );
}

//Constructor with parameters
public Point(double xValue, double yValue )
{
setPoint(xValue, yValue );
}

// set x and y coordinates of Point
public void setPoint(double xValue, double yValue )
{
x = xValue;
y = yValue;
}

// get x coordinate
public double getX()
{
return x;
}

// get y coordinate
public double getY()
{
return y;
}

// convert point into String representation
public String toString()
{
return "[" + String.format("%.2f", x)
+ ", " + String.format("%.2f", y) + "]";
}

//Method to compare two points
public boolean equals(Point otherPoint)
{
return(x == otherPoint.x &&
y == otherPoint.y);
}

//Method to compare two points
public void makeCopy(Point otherPoint)
{
x = otherPoint.x;
y = otherPoint.y;
}

public Point getCopy()
{
Point temp = new Point();

temp.x = x;
temp.y = y;

return temp;
}

// print method
public void printPoint()
{
System.out.print("[" + String.format("%.2f", x)
+ ", " + String.format("%.2f", y) + "]");
}

} // end class Point

class Circle
{
   private double radius;
   private Point p;
  
   public Circle(Point p, double radius)
   {
       this.p = p;
       this.radius = radius;
   }
   public void setRadius(double radius)
   {
       this.radius = radius;
   }
   public double getRadius()
   {
       return radius;
   }
   public double getArea()
   {
       return 3.14*radius*radius;
   }
   public double getCircumference()
   {
       return 2*3.14*radius;
   }
   public void printCircle()
{
System.out.print("Center :");
p.printPoint();
System.out.println(" Radius : "+radius +" Area : "+getArea() +" Circumference : "+getCircumference());
  
  
}
  
}
class Test
{
   public static void main (String[] args)
   {
       Point center = new Point(5.5, 4.7);
       Circle c = new Circle(center, 10.00);
      
       c.printCircle();
      
      
      
   }
}

Output:

Center :[5.50, 4.70] Radius : 10.0  Area : 314.0  Circumference : 62.800000000000004

Do ask if any doubt. Please up-vote.


Related Solutions

The questions in this assignment are about a circle with center at (-9, -12) and radius...
The questions in this assignment are about a circle with center at (-9, -12) and radius 15. The equation for the circle in function form is: y = ±√(225 - (x - 9)^2) - 12, however there may be mistakes in the equation. Identify all of the locations of mistakes. a) Find the intersections of the given circle with the y axis. What number is the y coordinate of the lower intersection? b) What number is the y coordinate of...
1. Find an equation of the circle that satisfies the given conditions. Center (2, −3); radius...
1. Find an equation of the circle that satisfies the given conditions. Center (2, −3); radius 5 2. Find an equation of the circle that satisfies the given conditions. Center at the origin; passes through (4, 6) 3. Find an equation of the circle that satisfies the given conditions. Center (2, -10); tangent to the x-axis 4. Show that the equation represents a circle by rewriting it in standard form. x² + y²+ 4x − 10y + 28 = 0...
Determine the center and radius and make the circle graph x^2 - 8x + y^2 -...
Determine the center and radius and make the circle graph x^2 - 8x + y^2 - 10y = -5
Find a path that traces the circle in the plane y=0 with radius r=2 and center...
Find a path that traces the circle in the plane y=0 with radius r=2 and center (2,0,−2) with constant speed 12. r1(s)=〈 , , 〉 Find a vector function that represents the curve of intersection of the paraboloid z=7x^2+5y^2 and the cylinder y=6x^2. Use the variable t for the parameter. r(t)=〈t, , 〉 Need help with Calculus III
1) A circle of radius r has area A = π r2. If a random circle...
1) A circle of radius r has area A = π r2. If a random circle has a radius that is evenly distributed in the interval (0, 1), what are the mean and variance of the area of ​​the circle? choose the correct answer A) 1/3 and 1/12 B) Pi/3 and 1/12 C) Pi/3 and 1/5 D) Pi/3 and (4/45)*Pi^2
Find the center and the radius of the circle whose graph passes through points (2,5) (-4,-3) and (3,4).
Solve by using elimination. Find the center and the radius of the circle whose graph passes through points (2,5) (-4,-3) and (3,4). Use the given equation x^2 + y^2 + ax + by + c= 0
How can you generate a circle of center C and radius R using Bresenhem’s algorithm? Also,...
How can you generate a circle of center C and radius R using Bresenhem’s algorithm? Also, make flow chart for this algorithm. Write a C/C++ program to implement Bresenhem’s circle algorithm.
The circle above is a wire loop of radius 0.85 m. It has a resistance of...
The circle above is a wire loop of radius 0.85 m. It has a resistance of 35 Ω. 1) If there is a constant magnetic field of 7.5 T into pointed into the page: a) What is the magnitude of the induced EMF in the loop? What is its direction? (clockwise or counterclockwise) b) What is the magnitude of the current in the loop? What is its direction? (clockwise or counterclockwise) 2)Assume that the magnetic field is initially 7.5 T...
A box with mass 0.0325 kg moves in a vertical circle that has a radius of...
A box with mass 0.0325 kg moves in a vertical circle that has a radius of 0.600 m on the inside of a circular track. When the box is at the bottom of its path, point A, the magnitude of the normal force exerted on the box by the track has magnitude 3.75 N. When the box reaches the top of its path, point B, the magnitude of the normal force exerted on the box has magnitude 0.665 N. How...
Zero, a hypothetical planet, has a mass of 5.2 x 1023 kg, a radius of 3.2...
Zero, a hypothetical planet, has a mass of 5.2 x 1023 kg, a radius of 3.2 x 106 m, and no atmosphere. A 10 kg space probe is to be launched vertically from its surface. (a) If the probe is launched with an initial kinetic energy of 5.0 x 107 J, what will be its kinetic energy when it is 4.0 x 106 m from the center of Zero? (b) If the probe is to achieve a maximum distance of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT