Imani G.

asked • 10/02/23

java instance methods creations

public Point2D copyOf()

This method creates and returns a new, distinct Point2D object with data copied from this Point2D object.


public Point2D add(Point2D other)

This method creates and returns a new, distinct Point2D object that is the sum of this Point2D object and the Point2D object referenced by other. For example, the sum of points (1, 2) and (3, 4) is a new point (4, 6).



public Point2D midpoint(Point2D other)

This method creates and returns a new, distinct Point2D object that is the midpoint of the line segment formed by this Point2D object and the Point2D object referenced by other. For example, the midpoint of points (1, 2) and (3, 4) is a new point (2, 3). This method assumes that both the x and y coordinates of the midpoint are integers.


NOTE: Do not make copies of the objects used in instance methods unnecessarily. While the add and midpoint method should change neither this Point2D object nor the Point2D object referenced by other, the operations required to create the new Point2D object with the appropriate data naturally do not modify them.

1 Expert Answer

By:

Tanya M. answered • 11/26/23

Tutor
4.8 (51)

Computer Science Tutor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.