Class Line

java.lang.Object
  extended by Line

public class Line
extends Object

This class models a line in a two-dimensional space.

Author:
CS133 Staff

Constructor Summary
Line(double slope, double yIntercept)
          Constructs a Line by initializing the slope and yIntercept instance variables.
 
Method Summary
 double evaluateAt(double xPosition)
          Treats this Line as a function and evaluates its y-value at the x-value given.
 double getSlope()
          Returns the slope of this Line.
 double getXIntercept()
          Returns the x-intercept of this Line.
 double getYIntercept()
          Returns the y-intercept of this Line.
 void invert()
          Changes this line to be its reflection in the line y = x.
 void shiftVertical(int yShift)
          Changes the position of this Line by shifting it yShift units vertically
 String toString()
          Returns a String representation of this Line in y = mx + b format where m is the slope and b is the y-intercept.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Line

public Line(double slope,
            double yIntercept)
Constructs a Line by initializing the slope and yIntercept instance variables.

Parameters:
slope - The slope of this Line.
yIntercept - The y-coordinate of the y-intercept of this Line.
Method Detail

getXIntercept

public double getXIntercept()
Returns the x-intercept of this Line.

Returns:
This Line's x-intercept.

getYIntercept

public double getYIntercept()
Returns the y-intercept of this Line.

Returns:
This Line's y-intercept.

getSlope

public double getSlope()
Returns the slope of this Line.

Returns:
This Line's slope.

toString

public String toString()
Returns a String representation of this Line in y = mx + b format where m is the slope and b is the y-intercept.

Overrides:
toString in class Object
Returns:
The equation of this Line.

shiftVertical

public void shiftVertical(int yShift)
Changes the position of this Line by shifting it yShift units vertically

Parameters:
yShift - The number of units to shift the Line.

invert

public void invert()
Changes this line to be its reflection in the line y = x.


evaluateAt

public double evaluateAt(double xPosition)
Treats this Line as a function and evaluates its y-value at the x-value given.

Parameters:
xPosition - The x-value at which to evaluate the function.
Returns:
The value of y when this Line passes through xPosition.