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

Write a class encapsulating the concept of a circle, a circle has the following

ID: 3885664 • Letter: W

Question

Write a class encapsulating the concept of a circle, a circle has the following attributes: a Point representing the center of the Circle, and a none negative number-the radius of the circle. Include constructor, the accessors and mutators, perimeter, area methods, and overwrite toString methods. Here are the outline of the classes you need to define: Circle (the class name must be named as Circle.java): data member: center (Point type), radius (double) constructor: takes two parameter (Point center, double radius) and the no parameter constructor which sets its center to (1.0, 1.0) and radius to 1.0 a circle radius must be within the range (0, 25], otherwise set to its default radius (1.0) methods: all getter and setter methods perimeter returns the perimeter of the circle area return the area of the circle toString returns the circle information as follows: Radius: 1.00 Center[1.00, 1.00] Perimeter: 6.28 Area: 3.14 Point (must be named as Point.java): data member: x (double for x-axis) and y (double for y-axis) All getter and setter methods constructor: two parameters to set x and y, and a no parameter constructor with default value: x=0 and y=0; Overwrite toString method which returns the point information as follows: [1.00, 1.00] CircleTester(driver class to test your classes) 1. Create a java file named CircleTester.java 2. Open the file named CircleTester.txt, copy and paste the content to your CircleTester.java 3. Compile and run the CircleTester.java to test your Point and Circle classes If your Point and Circle classes are defined properly, the tester program should generate the following output: Radius: 2.00 Center[0.00, 0.00] Perimeter: 12.57 Area: 12.57 Radius: 10.00 Center[-1.00, -10.00] Perimeter: 62.83 Area: 314.16 Radius: 1.00 Center[2.00, -1.00] Perimeter: 6.28 Area: 3.14 Radius: 1.00 Center[-1.00, -10.00] Perimeter: 6.28 Area: 3.14 Radius: 25.00 Center[0.00, 0.00] Perimeter: 157.08 Area: 1963.50 Radius: 1.00 Center[0.00, 0.00] Perimeter: 6.28 Area: 3.14

Explanation / Answer

Point.java

public class Point {
//Declaring instance variables
private double x;
private double y;

//Zero argumented constructor
public Point() {
this.x = x;
this.y = y;
}

//Parameterized constructor
public Point(double x, double y) {
super();
this.x = x;
this.y = y;
}

//getters and setters
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "[" + x + " , " + y + "]";
}

}

_________________

Circle.java

public class Circle {

//Creating a Point class reference

Point center;

//Declaring instance variables

private double radius;

//Zero argumented constructor

public Circle() {

center = new Point(1.00, 1.00);

this.radius = 1.0;

}

//Parameterized constructor

public Circle(Point center, double radius) {

super();

this.center = center;

if (radius <= 0 || radius > 25) {

this.radius = 1.0;

} else {

this.radius = radius;

}

}

//getters and setters

public double getRadius() {

return radius;

}

public void setRadius(double radius) {

this.radius = radius;

}

//This method will calculate the perimeter

public double perimeter() {

return 2 * 3.14159 * radius;

}

//This method will calculate the area

public double area() {

return 3.14159 * radius * radius;

}

//toString method is used to display the contents of an object inside it

@Override

public String toString() {

return "Radius :" + getRadius() + " Center " + center.toString() + " Perimeter :" + perimeter() + " Area :" + area();

}

}

_____________________

CircleTester.java

public class CircleTester {

public static void main(String[] args) {

//Creating the Point class Objects
Point p1 = new Point(0.00, 0.00);

//Creating the Circle class objects
Circle c1 = new Circle(p1, 2.00);

//calling the toString method
System.out.println(c1);

Point p2 = new Point(-1.00, -10.00);
Circle c2 = new Circle(p2, 10.00);

System.out.println(c2);

Point p3 = new Point(2.00, -1.00);
Circle c3 = new Circle(p3, 1.00);

System.out.println(c3);

Point p4 = new Point(-1.00, -10.00);
Circle c4 = new Circle(p4, 1.00);

System.out.println(c4);

Point p5 = new Point(0.00, 0.00);
Circle c5 = new Circle(p5, 25.00);

System.out.println(c5);

Point p6 = new Point(0.00, 0.00);
Circle c6 = new Circle(p6, 1.00);

System.out.println(c6);

}

}

______________________

Output:

Radius :2.0 Center [0.0 , 0.0] Perimeter :12.56636 Area :12.56636
Radius :10.0 Center [-1.0 , -10.0] Perimeter :62.8318 Area :314.159
Radius :1.0 Center [2.0 , -1.0] Perimeter :6.28318 Area :3.14159
Radius :1.0 Center [-1.0 , -10.0] Perimeter :6.28318 Area :3.14159
Radius :25.0 Center [0.0 , 0.0] Perimeter :157.0795 Area :1963.4937499999999
Radius :1.0 Center [0.0 , 0.0] Perimeter :6.28318 Area :3.14159

________________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote