Question
not sure where to go from here. Any help would be appreciated. public class myPoint { private int x; private int y; myPoint(){ x =
not sure where to go from here. Any help would be appreciated.
public class myPoint { private int x; private int y; myPoint(){ x = 0; y = 0; }
myPoint (int x, int y) { this.x = x; this.y = y; } int getX() { return this.x; } void setX(int x) { this.x = x; } int getY() { return this.y; } void setY(int y) { this.y = y; } void setXY(int x, int y) { this.x = x; this.y = y; } public String toString() { return "[" + x + ":" + y + "]"; }
public double distance(int x, int y) { double tbeDistance = 0; theDistance = Math.sqrt((this.x-x)*(this.x-x)+(this.y-y)*(this.y-y)); return theDistance; } public double static boolean (myPoint another) { }
}
Develop a class called MyPoint, which models a point in 2D plane with x and y coordinates, as is shown in the class diagram. It contains: Toanceviablesdesenng ie Ce coedinates of A "no-argument (or "no-arg") constructor that construct a point at (o, 0). A constructor that constructs a point with the given x and y coordinates. Getter and setter for the instance variables x and y A method setXY () to set both x and y A tostring method that returns a string description of the instance in the format (x, y method called distance (int x, int y) that returns the distance from this point to another point at the given (x, y) coordinates An overloaded distance (MyPoint another) that returns the distance from this point to the given MyPoint instance another You are required to: Write the code for the class MyPoint. Make an array of 5 MyPoint objects Write a static boolean method contains() that takes as parameters an array of MyPoint 2. 3. arr, and one Mypoint, p. It returns true if the array arr contains myPoint p. (two myPoints are considered equal if both their instance variables x and y, are equal. Write a static boolean method horizontalo that takes as a parameter an array of Nypoint l returns true if the points are all on a horizontal line. 5. Write a main0) method that tests your class MyPoint by running tests on all the methods defined in the classStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started