freeresponse2010
Class APLine

java.lang.Object
  extended by freeresponse2010.APLine

public class APLine
extends java.lang.Object

Encapsulates a line of the form ax + by + c = 0, where a, b and c are integers, and a and b are non-zero. This is a sample solution to free response question #2 on the AP Computer Science 2010 exam.


Field Summary
private  int aaa_
          Coefficient for the x term in ax + by + c = 0.
private  int bbb_
          Coefficient for the y term in ax + by + c = 0.
private  int ccc_
          c term in ax + by + c = 0.
 
Constructor Summary
APLine(int aaa, int bbb, int ccc)
          Constructs an object representing a line in the form ax + by = c.
 
Method Summary
 double getSlope()
          Gets the slope of the encapsulated line.
 boolean isOnLine(int xco, int yco)
          Determines whether a point is on the encapsulated line.
 java.lang.String toString()
          Returns a string representation of the encapsulated line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

aaa_

private int aaa_
Coefficient for the x term in ax + by + c = 0.


bbb_

private int bbb_
Coefficient for the y term in ax + by + c = 0.


ccc_

private int ccc_
c term in ax + by + c = 0.

Constructor Detail

APLine

public APLine(int aaa,
              int bbb,
              int ccc)
Constructs an object representing a line in the form ax + by = c.

Parameters:
aaa - Coefficient for the x term in ax + by + c = 0.
bbb - Coefficient for the x term in ax + by + c = 0.
ccc - c term in ax + by + c = 0.
Precondition:
s != 0, b != 0
Method Detail

getSlope

public double getSlope()
Gets the slope of the encapsulated line.

Returns:
The slope of the encapsulated line.

isOnLine

public boolean isOnLine(int xco,
                        int yco)
Determines whether a point is on the encapsulated line.

Parameters:
xco - x coordinate of point to test.
yco - y-coordinate of point to test.
Returns:
true if the point is on the line, false otherwise.

toString

public java.lang.String toString()
Returns a string representation of the encapsulated line. Not a part of the AP specification; added to facilitate testing.

Overrides:
toString in class java.lang.Object