Class Point
- java.lang.Object
-
- Point
-
public class Point extends java.lang.Object
Point.java This program implements the following extension of Programming Project 3.4 (page 101):
Defines a class, named Point, to represent a point on the Cartesian plane, making use of the point's x and y coordinates, both of type double.- Author:
- CS230 Staff (SK)
-
-
Field Summary
Fields Modifier and Type Field Description (package private) double
TOLERANCE
-
Constructor Summary
Constructors Constructor Description Point(double xCoord, double yCoord)
Given two doubles, it creates a Point.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
areEquidistant(Point p2, Point p3)
Checkes whether this point is at equal distance from the two inputted points.
Returns true if the two points are practically equidistant, i.e.double
findDistance(Point other)
Finds and returns the distance between this (the invoking) point and the input one.double
getX()
Returns the x-coordinate of this point.double
getY()
Returns the y-coordinate of this point.static void
main(java.lang.String[] args)
Driver method, used to test the class.static Point
readPoint(java.util.Scanner s)
Reads from the input scanner, two double numbers, to define a Point.void
setX(double newX)
Sets the x-coordinate of this point.void
setY(double newY)
Sets the y-coordinate of this point.java.lang.String
toString()
Provides a string representation of a Point
-
-
-
Field Detail
-
TOLERANCE
final double TOLERANCE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getX
public double getX()
Returns the x-coordinate of this point.- Returns:
- The x-coordinate of this point
-
setX
public void setX(double newX)
Sets the x-coordinate of this point.- Parameters:
newX
- The new x-coordinate of this point
-
getY
public double getY()
Returns the y-coordinate of this point.- Returns:
- The y-coordinate of this point
-
setY
public void setY(double newY)
Sets the y-coordinate of this point.- Parameters:
newY
- The new y-coordinate of this point
-
findDistance
public double findDistance(Point other)
Finds and returns the distance between this (the invoking) point and the input one.- Parameters:
other
- The other point- Returns:
- The distance between this point and the inputed one
-
areEquidistant
public boolean areEquidistant(Point p2, Point p3)
Checkes whether this point is at equal distance from the two inputted points.
Returns true if the two points are practically equidistant, i.e. their distance is less than TOLERANCE, false otherwise.- Parameters:
p2
- The second pointp3
- the third point- Returns:
- true if the second point and the third point have -practically- the same distance from this point
-
readPoint
public static Point readPoint(java.util.Scanner s)
Reads from the input scanner, two double numbers, to define a Point. It's used within the main().- Parameters:
s
- the Scanner object to be used for reading user input- Returns:
- The point entered by the user
-
toString
public java.lang.String toString()
Provides a string representation of a Point- Overrides:
toString
in classjava.lang.Object
- Returns:
- The object state
-
main
public static void main(java.lang.String[] args)
Driver method, used to test the class.
-
-