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 equation ax + by + c = 0,where a is not equal to zero, b is not equal to
zero, and a, b, and c are all integers. The slope of an APLine is defined to be the double value -a / b . 
A point (represented by integers x and y) is on an APLine if the equation of the APLine is satisfied when
those x and y values are substituted into the equation. That is, a point represented by x and
y is on the line if ax + 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
Copyright © StudyCS 2024 All rights reserved.