Question: I need some help writing this java program! Define a Point2D class which is a point in 2D coordinate system. The class contains: Data fields:

I need some help writing this java program!

Define a Point2D class which is a point in 2D coordinate system. The class contains:

Data fields:

x (double), private

y (double), private

The default values for these 2 variables are both 0.0.

Methods:

(1) A no-arg constructor that creates a default Point2D object.

(2) A constructor that creates a Point2D object with specified x and y coordinates.

(3) Getter method and Setter method to get and change x-coordinate.

(4) Getter method and Setter method to get and change y-coordinate.

(5) A method named getDistance() to calculate the distance from this point to the original point (0.0, 0.0).

(6) A method name getDistance(Point2D pt) to calculate the distance from this point to another point specified parameter pt

(7) A method toString() which returns the following text message Point(x-coord, y-coord). x-coord, and y-coord are replaced by values stored in member x and y.

Test:

Create a test class, in this class:

(1) Create an array of Point2D type.

(2) Create Point2D objects and store these objects in above array. Display these points (call toString())

(3) For each point in the array, display distance of this point to the original point.

SCCC CSE148, Spring 2021

(4) Define a method in Testnamed findClosestPointToOrignal(). Pass above array to this method as input parameter. Return the point which is closest to the original point.

Call this method in main() and display result returned from the method.

(5) Define a method named findClosestPoints(). Pass above array to the method as input parameter. Return 2 points in the array which are closest to each other. Return these 2 points from the method.

Call this method in main() and display result returned from the method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!