Write a public class named Point.
Write a main method that does the traditional thing of
printing "hello, world!".
Add two double instance variables named x
and y. They should be—as most instance variables
are—private.
Write a constructor that takes two double
arguments, x and y, and initializes the
corresponding instance variables.
Write a method, distanceFromOrigin, that takes no arguments
and returns a double representing the distance of the point
from the origin (0,0). You can use
the Math.hypot
method which takes two arguments and returns the hypotenuse of a triangle
with those values as legs, i.e. Math.hypot(a, b) is an easier
way to compute Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)).
Write a method, distanceTo, that takes
another Point as its single argument and returns
a double representing the distance between the current point
and the other. You can use
the Math.hypot
method described in the previous problem.
Write a method, move, that takes two double
arguments representing a change in x and change in y and changes
the x and y of the point by the corresponding
amounts.
Write a method, midwayTo, that takes
another Point as its single argument and returns a
new Point representing the point midway between the current
point and the other. You can compute the x coordinates of this new point
by averaging the x coordinates of the two points and likewise for the y.
Write a toString method that returns a String of
the form "Point<2,3>" where 2 and 3 are the x and y values of
the Point.
Add a public static final variable named ORIGIN
representing the point at 0,0.
In your main method add code to create a Point
at 300,400. Then compute the Point midway between that point
and the origin. Finally, add code so your output is of the form:
hello world!
p: the first point
midpoint: the midpoint between the two
distance from origin: the distance between the original point and the origin
to midpoint: the distance between the originial point and the midpoint
Note: the above shows how the output should be broken into lines. The “got” and “expected” columns in the test results will not show the proper line breaks.