In BlueJ create a new Java project named "project-3" with two classes, MyPoint.java and Main.java:
MyPoint
class exactly as
per the instructions in the textbook with both distance()
methods
(maximum grade for completing this full credit project is 10
out of ten (10) points)
distance()
method are as follows:distance(double, double)
takes values for parameters
x
and y
, and calculates and returns the distance
between the two points using the formula above
distance(MyPoint)
takes a parameter value for
a MyPoint
object, passes its x- and y-coordinate instance variables
to the first distance(double, double)
method and returns the distance
returned from that methodMath
class from the
Java API libary to find a method that returns the square root of a numberMyPoint
class only include the
second distance()
method, the one that takes the two double
parameters x
and y
and returns the distance from this point object to that
of the x- and y-coordinate parameters (this is a partial credit
assignment--maximum grade for completing the project with this modification is
9; out of ten (10) points)distance()
methods from your MyPoint class for an additional one-and-one-half
(1½) point deduction (maximum grade for completing the project
with this modification is 7½ out of ten (10) points)
- The two instance variables,
x
andy
, are both typedouble
- There should be two constructors, the first which makes a call to the
this
constructor and creates a default object with default values; since there is no mention of set methods in the textbook assignment, assign the values of thex
andy
parameters directly to the instance variables in this second constructor, e.g. objects instantiated from the class are immutable (there is no validation required forx
andy
since negative values are valid for both coordinates)
- All statements in the class that reference data members (e.g. in the
distance()
andtoString()
methods) should call the get methods of the classes (do not reference data members directly which is the Java standard)
- Include a
toString()
method that returns aString
representation of the class which should be a formatted representation of the x and y coordinates in the format (assuming that the current instance variable values are x = 10 and y = 30.5):
MyPoint coordinates: x = 10.0; y = 30.5
- Within class Main in the
main()
method include the following test operations:
- Instantiate two objects of the class, one using the no-parameter constructor with default values zero (0) for both the
x
andy
instance varibles and the other that passes actual values to the second (double
,double
) constructor- Use the
showMessageDialog()
method of classJOptionPane
to display thereturn
values of thetoString()
methods of both objects; additionally in theshowMessageDialog()
call thedistance()
method with a descriptive label depending upon which version of the project you are completing; for example:
MyPoint coordinates: x = 0.0; y = 0.0
MyPoint coordinates: x = 10.0; y = 30.5
Distance: 32.0975
@author
comment and the assignment due date
for the @version
comment that already exist at the top of the new class
@param
and @return
tagsmain()
method