Question: Using the PointList class, write a Java program which will allow the user to enter a set of points from the 2D Cartesian plane and
Using the PointList class, write a Java program which will allow the user to enter a set of points from the 2D Cartesian plane and find out certain things about this set of points. The user gets to choose how many points they want to enter during any given run of the program as long as they enter 3 or more points. The program should store the points entered by the user in a PointList object.
After the points are entered by the user, the user gets to choose from the following menu items. The functionality for the menu items should be implemented as methods in your PointList class:
1. Determine if 3 points can create a triangle and the type of triangle it would be.
2. Determine the point which is the farthest outlier to the other points.
3. Find the upper left and lower right points of the smallest rectangle that can contain all the points
4. Exit
Here are some additional implementation details for the 3 menu items:
1. The user should be able to pick the 3 points they want to use. If you determine a triangle can be made, tell the user that and output whether the triangle is acute, right, or obtuse. If a triangle can't be formed, tell the user it can't be formed.
2. The farthest outlier can be determined by the largest total distance to all other points.
3. The points can be on the edge of the rectangle you find.
Here is the PointList class. In the question, what I was referring to was just meant to be the class separate from the main class that has the methods listed above in it to be called in the main class through a menu, but I'll post it anyway in case it has any info that would make answering the question easier:
import java.util.Scanner; class PointList{ //data member double points[][]; //constructor public PointList(int len){ points = new double[len][2]; Scanner input = new Scanner(System.in); for (int i = 0; i < len; i++) { System.out.println("Enter the coordinates of a point:"); System.out.println("Enter the x value: "); points[i][0] = input.nextDouble(); System.out.println("Enter the y value: "); points[i][1] = input.nextDouble(); } } //close constructor //method to find distance between two points public double distance(double x1, double y1, double x2, double y2){ return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } //find the pair of points that has the smallest distance between them public void findClosestPair(){ int p1 = 0, p2 = 1; double shortDist = distance(points[p1][0], points[p1][1], points[p2][0], points[p2][1]); for (int i = 0; i < points.length; i++) { for (int j = i+1; j < points.length; j++) { double dist = distance(points[i][0], points[i][1], points[j][0], points[j][1]); if(shortDist>dist){ p1=i; p2=j; shortDist = dist; } } } System.out.println("The closest two points are ("+ points[p1][0]+", "+points[p1][1]+") and (" + points[p2][0]+", "+points[p2][1]+")"); } } public class a0926 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("How many points do you want to compare?"); int size = input.nextInt(); PointList p1 = new PointList(size); double x1 = p1.points[0][0]; double y1 = p1.points[0][1]; double x2 = p1.points[1][0]; double y2 = p1.points[1][1]; System.out.println("The distance between the first two points is "+p1.distance(x1,y1,x2,y2)); p1.findClosestPair(); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
