Question: USING THESE METHODS Point add (Point otherPoint) Returns the result of adding two points double distance (Point otherPoint) Returns the distance between two points boolean
USING THESE METHODS
| Point | add(Point otherPoint) Returns the result of adding two points |
| double | distance(Point otherPoint) Returns the distance between two points |
| boolean | equals(Point otherPoint) Returns the result of checking the equality of two point -- two points are equal if their x and y coordinates are equal |
| Point | originReflection() Returns the point obtained by a reflection of this point through the origin |
| int | quadrant() Returns the quadrant (1, 2, 3, 4, or 0) that this point resides in |
| static Point | read(java.util.Scanner scanner) Returns a newly created Point object initialized with x,y values read from the scanner |
| java.lang.String | toString() Returns a string representation of the point in the form (x, y) |
| Point | xReflection() Returns the point obtained by a reflection of this point across the x-axis |
| Point | yReflection() Returns the point obtained by a reflection of this point across the y-axis |
Code an application class (i.e., a class containing a main method), named PointApp that reads point data from the file points.text. This data is then used to create pairs of Point objects which are then used to flex (i.e, illustrate) the methods of the class. USING THESE METHODS
The format of the points.txt file is:
x1 y1 x2 y2
i.e., pairs of x/y coordinates, resulting in data for 2 Point objects per line.
The name of your class should be PointApp.
For example, if the file points.text contains:
0 0 1 1 1 1 1 -1 1 1 -1 1 1 1 -1 -1 0 0 0 0 1 1 1 1 1 1 -2 -2
the program should produce exactly the following output:
p1: (0, 0) (quadrant 0) / p2: (1, 1) (quadrant 1) p1+p2: (1, 1) (quadrant 1) The distance between (0, 0) and (1, 1) is 1.4142135623730951 p1: (1, 1) (quadrant 1) / p2: (1, -1) (quadrant 4) p1+p2: (2, 0) (quadrant 4) p1 and p2 are reflections across the x-axis p1 and p2 are equidistant from the origin The distance between (1, 1) and (1, -1) is 2.0 p1: (1, 1) (quadrant 1) / p2: (-1, 1) (quadrant 2) p1+p2: (0, 2) (quadrant 0) p1 and p2 are reflections across the y-axis p1 and p2 are equidistant from the origin The distance between (1, 1) and (-1, 1) is 2.0 p1: (1, 1) (quadrant 1) / p2: (-1, -1) (quadrant 3) p1+p2: (0, 0) (quadrant 0) p1 and p2 are reflections through the origin p1 and p2 are equidistant from the origin The distance between (1, 1) and (-1, -1) is 2.8284271247461903 p1: (0, 0) (quadrant 0) / p2: (0, 0) (quadrant 0) p1+p2: (0, 0) (quadrant 0) p1 and p2 are reflections across the x-axis p1 and p2 are reflections across the y-axis p1 and p2 are reflections through the origin p1 and p2 are equidistant from the origin The distance between (0, 0) and (0, 0) is 0.0 p1: (1, 1) (quadrant 1) / p2: (1, 1) (quadrant 1) p1+p2: (2, 2) (quadrant 1) p1 and p2 are equidistant from the origin The distance between (1, 1) and (1, 1) is 0.0 p1: (1, 1) (quadrant 1) / p2: (-2, -2) (quadrant 3) p1+p2: (-1, -1) (quadrant 3) The distance between (1, 1) and (-2, -2) is 4.242640687119285
USE CLASS METHODS AS PRESENTED ABOVE and below
add
public Point add(Point otherPoint)
Returns the result of adding two points
Parameters:
otherPoint - the point to be added to the receiver
Returns:
a Point object containing the sum of the two points
distance
public double distance(Point otherPoint)
Returns the distance between two points
Parameters:
otherPoint - the point whose distance from the receiver is to be calculated
Returns:
a double representing the distance between the two points
xReflection
public Point xReflection()
Returns the point obtained by a reflection of this point across the x-axis
Returns:
a Point object containing the reflection across the x-axis of this point
yReflection
public Point yReflection()
Returns the point obtained by a reflection of this point across the y-axis
Returns:
a Point object containing the reflection across the y-axis of this point
originReflection
public Point originReflection()
Returns the point obtained by a reflection of this point through the origin
Returns:
a Point object containing the reflection of this point through the origin
quadrant
public int quadrant()
Returns the quadrant (1, 2, 3, 4, or 0) that this point resides in
Returns:
the quadrant this point resides in (1, 2, 3, or 4). If the point is the origin, 0 is returned.
equals
public boolean equals(Point otherPoint)
Returns the result of checking the equality of two point -- two points are equal if their x and y coordinates are equal
Parameters:
otherPoint - the point to be checked for equality with the receiver
Returns:
true if the points are equal; false otherwise
toString
public java.lang.String toString()
Returns a string representation of the point in the form (x, y)
Overrides:
toString in class java.lang.Object
Returns:
the string representation
read
public static Point read(java.util.Scanner scanner)
Returns a newly created Point object initialized with x,y values read from the scanner
Parameters:
scanner - The Scanner used to read the point's initial values
Returns:
The newly created Point object
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
