1.Define a class to hold information about a single point (Point class).
2.Write a method of the Point class to determine the distance to another Point.
3.Use composition to define a Circle.
4.Write a method of the Circle classes to determine if a Point is inside the Circle.
5.Write a method of the Circle classes to determine if a Circle is wholly inside another Circle.
6.Write a method of the Circle classes to determine if a circle surrounds another circle. Use the method above.
Write a new class called TestCircle, which contains the main method in order to test your classes. In the main method do the following tasks:
1.Create a circle object
2.Create a point object
3.Print the distance from that point to the centre of the circle.
4.Create a second circle object
5.Find out if the second circle is inside the first one.
Please answer all the Question with Comment
In case of any queries, please revert back.
class Point{
//We define the coordinates
public double x,y;
//Constructor to set the coordinates of point
public Point(double x1,double y1){
x=x1;
y=y1;
}
//get the distance between 2 points
public double getDist(Point p1,Point p2){
//dist=((x1-x2)^2 + (y1-y2)^2)^(1/2)
double dist=Math.pow(p1.x-p2.x,2)+Math.pow(p1.y-p2.y,2);
dist=Math.sqrt(dist);
return dist;
}
}
class Circle{
//centre is at point.
public Point centre;
public double radius;
//Constructor to Define Circle
public Circle(Point p1,double r1){
centre=p1;
radius=r1;
}
//Is point in Circle
public boolean isPointInCircle(Point p1){
//we find distance between centre and p1
double dist=centre.getDist(centre,p1);
//if it is less than radius it is in otherwise out.
if(dist<radius){
return true;
}
else{
return false;
}
}
//is the original circle in other circle
public boolean isMyCircleInCircle(Circle C1){
//Find distance between 2 centres
double dist=centre.getDist(centre,C1.centre);
/*if the distance plus radius is less than radius of outer
circle,it is in the circle */
if(dist+radius<=C1.radius){
return true;
}
else{
return false;
}
}
//is the circle inside original circle
public boolean isCircleInMyCircle(Circle C1){
//Find distance between 2 centres
double dist=centre.getDist(centre,C1.centre);
/*if the distance plus radius is less than radius of outer
circle,it is in the circle */
if(dist+C1.radius<=radius){
return true;
}
else{
return false;
}
}
}
//You can use TestCircle instead here
public class Main
{
public static void main(String[] args) {
//Define a centre Point
Point centre1=new Point(2,2);
//Define a circle with centre c1 and radius 2
Circle C1=new Circle(centre1,2);
Point p1=new Point(3,7);
double distance=p1.getDist(p1,centre1);
System.out.println("distance between point and circle
is "+distance);
Point centre2=new Point(2,1);
Circle C2=new Circle(centre2,1);
boolean flag=C1.isCircleInMyCircle(C2);
System.out.println("Does This Circle Lie in C1?
"+flag);
}
}

1.Define a class to hold information about a single point (Point class). 2.Write a method of...
Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An instance variable named x of type int. An instance variable named y of type int. Declare a method named toString() Returns a string representation of the point. Constructor that accepts values of all data members as arguments. Define a Sub class named Circle. A Circle object stores a radius (double) and inherit the (x, y) coordinates of its center from its super class Point....
C++
Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...
Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...
Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { } //get method (Accessor Methods ) public double getRadius (...
Java Programming The following is about creating a class Fish and testing it. In every part, correct any syntax errors indicated by NetBeans until no such error messages. (i) Create a class Fish with the attributes name and price. The attributes are used to store the name and the price of the fish respectively. Choose suitable types for them. You can copy the class Counter on p.17 of the unit and modify the content. Copy the content of the file...
Java: Create a main method for your class, and then add another method to your class (above the main method) named fallingDistance. This method accepts an integer into its parameter t, which is the amount of time, in seconds, that an object has been falling. This method returns the distance, in meters, that the object has fallen during the time interval. When an object s falling because of gravity, we use the following formula to determine the distance the object...
Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able to store information regarding the name, age, gpa, and phone number of a Student object. Please write all the setter and getter methods. Finally, write a Demo class to demonstrate the use of the class by creating two different objects. 2.Use the same Student class from the previous problem. This time,you will write a different Demo class, in which you will create three Student...
Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables...
Complete the SpeedDating Class Write the method bodies for the 2 SpeedDating methods. Study the method declarations and Javadoc comments so that you understand what each method is supposed to do. To receive credit for a method, it must use one of the Java loops (your choice). Nested loops are not necessary. Write a Test Class for Your SpeedDating Class Your test class will have a main method that does the following: Create a SpeedDating object Since 1971, Columbus Day...