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.
Review the APLine free response problem with AP CS Tutor Brandon Horn.
APLine
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; } }
2010 AP CS Exam Free Response Solutions |
Recommended Practice Problems |
what is the this. for ?
The instance fields have the same names as the parameters to the constructor.
this.a
refers to the instance field.a
refers to the parameter.this.a = a
assigns the value of the parameter to the instance field.Another one . When you casted (double) to the slope , why did you just cast it to b ?
Thanks in advance .
When both operands are integers the
/
operator performs integer division. When either operand is a double the operator performs double division.