Question
Please code in java, thanks Here is the class Point class Points { //instance variable private double px; private double py; public Points(double px, double
Please code in java, thanks
Here is the class Point
class Points { //instance variable private double px; private double py;
public Points(double px, double py) { this.px = px; this.py = py; } public double getPx() { return px; }
public void setPx(double px) { this.px = px; }
public double getPy() { return py; }
public void setPy(double py) { this.py = py; } @Override public String toString() { return "Points [" + "px=" + px + ", py=" + py + ']'; } }
Here is the class Circle
class Circle { private double xpos; private double ypos; private double radius;
public Circle(double xpos, double ypos, double radius) { super(); this.xpos = xpos; this.ypos = ypos; this.radius = radius; } public double getXpos() { return xpos; } public double getYpos() { return ypos; } public double getRadius() { return radius; } public void setCenter(double xpos,double ypos) { this.xpos = xpos; this.ypos = ypos; } public void setRadius(double radius) { this.radius = radius; }
public boolean contain(Points P) { double discOfPoint = Math.sqrt(Math.pow(xpos-P.getPx(),2)+Math.pow(ypos-P.getPy(),2)); if(discOfPoint>radius) { return false; }else { return true; } } }
Inside of your Circle class, define a method contained(Rectangle r) that returns true if this Circle object is fully contained inside the given Rectangle object. The circle can touch the sides of the Rectangle but it must not intersect or lie outside. See examples below. Circle is contained Circle is contained Circle is not contained () Circle is not contained Algorithm Hint . If the Circle's center is not inside the Rectangle, then return false. If the Circle's center is inside the Rectangle, then check if the four points P1, P2, P3 and P4 shown in the figure below are contained in the Rectangle. If all four points are contained, then return true, otherwise false. The coordinates of these points can be easily determined from the Circle's center and the radius. For example, if the circle's center is the point (rx, ry), then the point P1 in the figure is given by (rx, ry - radius). The coordinates for P2, P3 and P4 can be found in a similar way. P1 P4 P2 P3 Then define a class called Demo3 that works as follows. It defines an arbitrary rectangle different from the example given below, whose sides are parallel to the x and y axes. Displays the data fields. Defines three circles with the following properties, and displays the data field. o A circle cl with the center lies outside of the rectangle. A circle c2 with the center lies inside of the rectangle, but is not contained in the rectangle. o A circle c3 with the center lies inside of the rectangle, and is contained in the rectangle. Calls contained (Rectangle r) method, and this method must correctly identify whether each one of these three circles is contained in the rectangle . Finally, provide the complete console output of the above three test cases (c1, c2, 3). A sample dialog and output is given below. Created one rectangle object: [xpos = 1, ypos = 1] width: 3, height: 2 Created one circle object:c1 [xpos = 3, ypos = 4] radius 2 Created one circle object:c2 [xpos = 1, ypos = 1] radius 3 Created one circle object:c3 [xpos = 2, ypos = 2] radius 1 Is cl contained in the rectangle? false Is c2 contained in the rectangle? false Is c3 contained in the rectangle? true Marking rubric . 0.25 mark is deducted for missing one test case. . 0.25 mark is deducted for not displaying data fieldsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started