2010 AP Line

<< 2010CookieOrder | APQuestionsTrailIndex | 2010Trail >>

question

APLine.java


public class APLine
{
   /**
    * Declare your instance variables
    */


    /**
     * Constructor for APLine must have 
     * three integer parameters that represent
     * a, b, and c, in that order
     * for ax+by+c=0
     */
    public APLine(int a, int b, int c)
    {

    }
    /**
     *  getSlope  
     * 
     * @return     the slope of the line 
     */
    public double getSlope()
    {
        return 0;
    }
    /**
     * isOnLine
     * @param x
     * @param y
     * @return true if point (x,y) is on line
     */
    public boolean isOnLine(int x, int y)
    {
        return false;
    }
}

APLineTester.java


public class APLineTester
{
   public static void main(String[] args)
   {
       APLine line1 = new APLine(5, 4, -17);
       double slope1 = line1.getSlope();	// slope1 is assigned -1.25
       boolean onLine1 = line1.isOnLine(5, -2); // true because 5(5) + 4(-2) + (-17) = 0

       System.out.println("slope1 should be -1.25: "+slope1);
       System.out.println("onLine1 should be true: "+onLine1);


       APLine line2 = new APLine(-25, 40, 30);
       double slope2 = line2.getSlope();	// slope2 is assigned 0.625
       boolean onLine2 = line2.isOnLine(5, -2); // false because -25(5) + 40(-2) + 30 &#8800; 0

       System.out.println("slope2 should be 0.625: "+slope2);
       System.out.println("onLine2 should be false: "+onLine2);

    }
}