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

Point Class: Design a class named Point to represent a point with x- and y- coor

ID: 3697173 • Letter: P

Question

Point Class:

Design a class named Point to represent a point with x- and y- coordinates. The class contains:

The private data fields x and y that represent the coordinates with getter methods. Use the “this” keyword to reference the object’s instance members (e.g. this.X, this.Y) and to invoke another constructor of the same class, for example,

public Point(){

this(0,0);

}

A no-arg constructor that creates a point (0,0).

A constructor that constructs a point with specific coordinates.

A static method named distance that returns the distance from this point object to another point object with specific x and y values.

Open Microsoft Word, and create the UML diagram for the class and then implement the class.   Write a test program called TestPoint that asks for the coordinates of two points, creates two point objects, and then displays the distance between them. You should use the Pythagorean Theorem to calculate this distance (see below). You should use the following showInputDialog method and the showMessageDialog method in the JOptionPane class and the StringTokenizer class from the java.util package along with the parseInt method from the Integer wrapper class (see example below):

String input = JOptionPane.showInputDialog("Enter x1 y1 x2 y2:");

                     StringTokenizer st = new StringTokenizer(input, " ");

                     int x1 = Integer.parseInt(st.nextToken());

String output = "The distance between the two points…

JOptionPane.showMessageDialog(null, output);

The distance between the two points: c = (a^2+b^2 ) = (4^2+3^2 ) = 25 = 5

c = ((x2-x1)^2+(y2-y1)^2 )

c = ((4-0)^2+(3-0)^2 ) = (16+9) = 25 = 5

Explanation / Answer

Any queries please comment ...values given below can be changed as per ur requirement

public class Point
{
public static void main(String[] args)
{
System.out.println("Distance between (0,0) and (0,9.2) is " + new MyPoint().distance(new MyPoint(0, 9.2)) + " units.");
}
}
class MyPoint
{
private double gottenX;
private double gottenY;
private double getX()
{
return gottenX;
}
private double getY()
{
return gottenY;
}
MyPoint()
{
gottenX = 0;
gottenY = 0;
}
MyPoint(double x, double y)
{
gottenX = x;
gottenY = y;
}
private double distance(double sentX, double sentY)
{
return Math.sqrt((Math.pow((gottenX - sentX), 2) + Math.pow((gottenY - sentY), 2)));
}
public double distance(MyPoint otherPoint)
{
return distance(otherPoint.getX(), otherPoint.getY());
}
}

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