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...
A circle of radius r has area A = πr2. If a random circle has a...
A circle of radius r has area A = πr2. If a random circle has a radius that is uniformly distributed on the interval (0, 1), what are the mean and variance of the area of the circle? Change the distribution of the radius to an exponential distribution with paramter β = 2. Also find the probability that the area of the circle exceeds 3, if it is known that the area exceeds 2.
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
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT