The APLine problem from the 2010 AP Computer Science Exam is unusually easy. The problem requires you to write a simple class in response to a prompt that contains client code.

APLine is #2 from the 2010 AP Computer Science Free Response.

https://secure-media.collegeboard.org/apc/ap10_frq_computer_science_a.pdf

APLine class

public class APLine
{
    private int a, b, c;

    public APLine(int a, int b, int c)
    {
        this.a = a;
        this.b = b;
        this.c = c;
    }

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

    public boolean isOnLine(int x, int y)
    {
        return a * x + b * y + c == 0;
    }
}

See Class writing order for a technique to respond to AP CS FR that request an entire class.

Storing slope as an instance variable is a common mistake. Do not store instance variables with values that can be calculated from the values of other instance variables. See Duplicate data as instance variables for additional discussion. In the absence of an effect on behavior, the scoring guide does not penalize this mistake.

2010 AP CS Exam Free Response Solutions

Help & comments

Get help from AP CS Tutor Brandon Horn

Comment on APLine