Java Reference
In-Depth Information
// Retrieve the x coordinate
public double getX() {
return x;
}
// Retrieve the y coordinate
public double getY() {
return y;
}
// Set the x coordinate
public void setX(double inputX) {
x = inputX;
}
// Set the y coordinate
public void setY(double inputY) {
y = inputY;
}
// Coordinates of the point
private double x;
private double y;
}
Directory "Geometry"
Note that you have added the getX() , getY() , setX() , and setY() methods to the class to make the
private data members accessible.
The Line class also needs to be amended to make the methods public and to declare the class as public.
You have to change its intersects() method so that it can access the private data members of Point
objects using the set...() and get...() methods in the Point class. The code in Line.java , with
changes highlighted, is:
package Geometry;
public class Line {
// Create a line from two points
public Line(final Point start, final Point end) {
this.start = new Point(start);
this.end = new Point(end);
}
// Create a line from two coordinate pairs
public Line(double xStart, double yStart, double xEnd, double yEnd)
{
Search WWH ::




Custom Search