Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class named MyPoint to represent a point with x andy-coordinates. The c

ID: 3607792 • Letter: D

Question

Design a class named MyPoint to represent a point with x andy-coordinates. The class contains: //Two data fields x and y that represent thecoordinates. //A no-arg constructor that creates a point (0,0) //A constructor that constructs a point with specifiedcoordinates. //Two get methods for data fields x and y, respectively. //A method named distance that returns the distance from thispoint to another point with specified x and y-coordinates. Draw the UML diagram for the class. Implement the class. Writea test program that creates two points (0,0) and (10, 30.5) anddisplays the distance between them. Design a class named MyPoint to represent a point with x andy-coordinates. The class contains: //Two data fields x and y that represent thecoordinates. //A no-arg constructor that creates a point (0,0) //A constructor that constructs a point with specifiedcoordinates. //Two get methods for data fields x and y, respectively. //A method named distance that returns the distance from thispoint to another point with specified x and y-coordinates. Draw the UML diagram for the class. Implement the class. Writea test program that creates two points (0,0) and (10, 30.5) anddisplays the distance between them.

Explanation / Answer

//Here is the implementation injava. //Hope this will help you..Don't forget to rate this answer.. /* MyPointTest.java */ class MyPoint { private double x,y; public MyPoint(){ x=y=0; } public void setP(double x1,double y1){ x=x1; y=y1; } public double getX() { return x; } public double getY() { return y; } public double getD(double x1,double y1) { double d; d= Math.sqrt((y1-y)*(y1-y) + (x1-x) * (x1-x)); return d; } }; class MyPointTest { public static void main(String args[]) { MyPoint mp = new MyPoint(); System.out.println("Distance is :" + mp.getD(2,30.5)); } } /* Sample output Distance is :30.56550343115585 */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote