2010 AP CSA FRQ 2: APLine - Solution

2010 AP CSA FRQ 2: APLine

Topic: Complete Class Design

Skills: Class implementation, constructor, accessor methods, mathematical calculations

Unit: Unit 3 (Class Creation) (2025-2026 AP CSA)

Points: 9 | Time: ~22 minutes

Study Guide: Unit 3: Class Creation

Part (a)

Write the complete APLine class representing a line ax + by + c = 0.

Try First! Attempt before viewing solution.

Solution

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;
    }
}

Part (b)

Note: This was a single-part question requiring the complete class.

Solution

// Key insight: DO NOT store slope as instance variable
// Calculate it from a and b when needed
// Cast to double to avoid integer division

Key Concepts

✓ Store only essential data (a, b, c), not derived values
✓ Cast to double before division to avoid truncation
✓ Use this keyword when parameter names match fields
✓ Equation ax + by + c = 0 means point is on line

Common Mistakes

Storing slope as instance variable (redundant data)
Integer division in getSlope (missing cast)
Wrong slope formula (should be -a/b)
Not using this keyword when needed

Official Resources

Author: Tanner Crow - AP CS Teacher, 11+ years

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]