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
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 objects 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
