Question
Complete the following code segment such that your implementation of class Point supports the operations used in the main method. The methods that are needed
Complete the following code segment such that your implementation of class Point supports the operations used in the main method. The methods that are needed in the Point class are listed in the main method. Sample run Input:
3 4 5 4 1 1 -1 -1 0 0 0 -1
Output:
3.605551275463989 6.4031242374328485 5.0 5.830951894845301 2
// TEST
import java.util.Scanner; import geometric.Point;
public class Test { public static void main(String[] args) { Scanner stdin = new Scanner(System.in);
double x = stdin.nextDouble(); double y = stdin.nextDouble();
// declare origin and initialize it with x and y // your code starts here
// your code ends here
double threshold = stdin.nextDouble();
Point[] pts = new Point[stdin.nextInt()];
for (int i = 0; i < pts.length; i++) { // call a constructor that initialize the x and y pts[i] = new Point(stdin.nextDouble(), stdin.nextDouble()); // distance method compute the distance from origin to another point System.out.println(origin.distance(pts[i])); }
// the within method in the Point class will count the number of // points in pts whose distance from origin is smaller than the // threshold System.out.println(origin.within(pts, threshold));
} }
// POINT
package geometric;
// your code starts here
// your code ends here
Step 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