CS 5004 Defining a 2D Point Java Version solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

This problem will give you an opportunity to create class representing a point in 2D Cartesian space in both C++ and Java. This will enable you to become familiar with the two languages and explore the similarities and differences in the languages.

Begin by implementing the C++ version after lecture 2, then create the Java implementation after lecture 3.

Important note: There are a number of implementations of a 2D point available on the web in both C++ and Java. By doing this exercise yourself, without consulting them, you will gain valuable experience implementng classes in C++ and Java that you will not gain by simply copying someone else’s code.
Java Version
Define a Java class Point2D in the package “edu.northeastern.cs_5004” The class represents a point in 3D Cartesian space. Define the following private fields:

Field name Type Description
final x float the X coordinate of the point
final y float the Y coordinate of the point
Define the following public methods:

Method name Type Parameters Description
Point2D none none Constructor initializes this.x and this.y to 0.0
Point2D none
float x
float y
Constructor initializes instance this.x and this.y to x, and y
Point2D none
Point2D point
Constructor intializes x and y to x and y of point (copy constructor)
getX float none Returns the x coordinate of the point
getY float none Returns the y coordinate of the point
getDistance float
Point2D point
Returns the distance between a point and this point
plus Point2D
Point2D
Returns Point2D representing sum of this point and another point†. The sum of two points is another point whose x and y values are the sum of the two point x and y values.
minus Point2D
Point2D point
Returns Point2D representing difference of this point and another point The difference of two points is another point whose x and y values are the difference of the two point x and y values.
minus Point2D none Returns Point2D representing a point with then negative of this point’s coordinates
equals bool
Object obj
Returns true if ‘obj’ is a Point2D that is equal to this point. Note that direct comparison of floats does not work correctly for float values of infinity and NaN (not-a-number). Try boxing x and y values as Float and calling equals() for each with other x and y values.
hashCode int none Returns int hash code for this point. Required when implementing equals(). A simple implemementation calls the utility function Objects.hash(f1,f2).
† For more on this operation, see Addition of Coordinates.

Define the class and implement its methods in “Point2D.java” in the subdirectory “edu/northeastern/cs_5004′. Create a JUnit test class with a main program in the file in “Point2D_main.java” that exercises the functionality of the Point2D class by creating points using both constructors, measuring their distances, and testing points for equality..

The class, fields, and function definitions, and test functions should have complete “Javadoc” style documentation. This follows the same style as we used with DOxygen for C and C++.