positiveSlopes
Practice traversing an array of objects and use object helper methods.
This problem is adapted from the 2010 FRQ #2 AP CSA Exam
Given an array of APLine
object, return the number of APLine
objects that have a positive slope (greater than 0).
TheAPLine
class is given below.
An APLine is a line defined by the equationax + by + c = 0
,wherea
is not equal to zero,b
is not equal to zero, anda
,b
, andc
are all integers. The slope of an APLine is defined to be the double value-a / b
.
A point (represented by integersx
andy
) is on an APLine if the equation of the APLine is satisfied when
thosex
andy
values are substituted into the equation. That is, a point represented byx
andy
is on the line ifax + by + c
is equal to 0.
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;
}
//return the slope.
public double getSlope(){
return -((double) a)/b;
}
}
Type your solution
Skills Practiced:
3.C
3.D
4.A
4.B
Saved
Saved