classwork
Class Line

java.lang.Object
  extended by classwork.Line

public class Line
extends java.lang.Object

Models a line.

Author:
Tom James

Field Summary
private  double b
          The x-intercept of the line.
private  double m
          The slope of the line.
private  boolean vertical
          Whether or not the line is vertical.
 
Constructor Summary
Line(double m, int b)
          Constructs a line given a slope and an x-intercept.
Line(int a)
          Constructs a line in the form x = a.
Line(int x, int y, double m)
          Constructs a line given a point and a slope.
Line(int x1, int y1, int x2, int y2)
          Constructs a line given two points.
 
Method Summary
 boolean equals(Line other)
           
 double getB()
           
 double getSlope()
           
 boolean intersects(Line other)
           
 boolean isParallel(Line other)
           
 boolean isVertical()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m

private double m
The slope of the line.


b

private double b
The x-intercept of the line.


vertical

private boolean vertical
Whether or not the line is vertical.

Constructor Detail

Line

public Line(int x,
            int y,
            double m)
Constructs a line given a point and a slope.

Parameters:
x - The x-coordinate.
y - The y-coordinate.
m - The slope.

Line

public Line(int x1,
            int y1,
            int x2,
            int y2)
Constructs a line given two points.

Parameters:
x1 - The first x-coordinate.
y1 - The first y-coordinate.
x2 - The second x-coordinate.
y2 - The second y-coordinate.

Line

public Line(double m,
            int b)
Constructs a line given a slope and an x-intercept.

Parameters:
m - The slope.
b - The x-intercept.

Line

public Line(int a)
Constructs a line in the form x = a.

Parameters:
a - The x-intercept of the vertical line.
Method Detail

getSlope

public double getSlope()
Returns:
The slope of the line.

getB

public double getB()
Returns:
The x-intercept of the line.

isVertical

public boolean isVertical()
Returns:
Whether or not the line is vertical.

intersects

public boolean intersects(Line other)
Parameters:
other - The other line to be tested.
Returns:
Whether or not the two lines intersect.

isParallel

public boolean isParallel(Line other)
Parameters:
other - The other line to be tested.
Returns:
Whether or not the lines are parallel.

equals

public boolean equals(Line other)
Parameters:
other - The other line to be tested,
Returns:
Whether or not the lines are the same.