Other 2010 FR Questions FR other years Be Prepared Home
A-2
public class APLine
{
  private int a, b, c;
  
  public APLine(int a1, int b1, int c1)
  {
    a = a1;
    b = b1;
    c = c1;
  } 1

  public double getSlope()
  {
    return -(double)a / b; 2
  }

  public boolean isOnLine(int x, int y)
  {
    return a*x + b*y + c == 0;
  }
}
Notes:
  1. Or:
      public APLine(int a, int b, int c)
      {
        this.a = a;
        this.b = b;
        this.c = c;
      }
  2. The cast to double on one or both operands is necessary to avoid integer division; casting the result to double would be too late.

Other 2010 FR Questions | Back to Contents

Copyright © 2010 by Skylight Publishing
support@skylit.com