Question: Implement a java class named Point that represents a two-dimensional point, with an x and y value. The Point class should have the following instance
Implement a java class named Point that represents a two-dimensional point, with an x and y value. The Point class should have the following instance variables (a.k.a. fields or data):
x (the x-value of the point, as a whole number) y (the y-value of the point, as a whole number)
The Point class will have methods to:
Create a new Point (given an x-value and y-value) [constructor] Create a new Point (from another Point) [copy constructor] getX getY setX setY distanceTo(Point otherPoint) equals [method to check if one Point is the same as another] toString [method to turn a Point into a string for display, e.g. display as "Point[x=0,y=5]" if the x-value is 0 and y-value is 5]
The distanceTo method can be implemented with the following equation for distance:
Now, implement a class named Line that represents a two-dimensional line, consisting of two points. The Line class should have the following instance variables (a.k.a. fields or data):
p1 (the first Point of the line) p2 (the last Point of the line)
The Line class will have methods to:
Create a new Line (from two x-values and two y-values) [constructor] Create a new Line (from two Points) [constructor] Create a new Line (from another Line) [copy constructor] getP1 getP2 getX1 getY1 getX2 getY2 setP1 setP2 setX1 setY1 setX2 setY2
length() [method that calculates the length of the Line] equals [method to check if one Line is the same as another] toString [method to turn a Line into a string for display, e.g. display as "Line[(x1=0,y1=5), (x2=0,y2=10)]"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
