01
Overview

A class with an array field plus stat methods.

When the data is fixed-size, an array field works; the class adds methods for total, max, count-above, and other statistics.

An array field (as opposed to ArrayList) suits classes where the data size is known and fixed: a fixed number of test scores, sensor readings, or grades. Stat methods loop over the array and compute totals, extremes, and counts.

On the AP exam, array-field classes appear in test-score, athletic-stat, and sensor FRQs.

02
Core Concept

Fixed array; methods loop over it.

One stat per method.

Scores class

public class Scores {
    private int[] scores;

    public Scores(int[] data) {
        this.scores = data;
    }

    public int total() {
        int sum = 0;
        for (int s : scores) sum += s;
        return sum;
    }

    public int max() {
        if (scores.length == 0) return 0;
        int m = scores[0];
        for (int s : scores) {
            if (s > m) m = s;
        }
        return m;
    }

    public int countAbove(int threshold) {
        int count = 0;
        for (int s : scores) {
            if (s > threshold) count++;
        }
        return count;
    }

    public double average() {
        if (scores.length == 0) return 0.0;
        return (double) total() / scores.length;
    }
}

One stat per method

Each method computes one statistic. Calls can be chained from the outside but each method stays focused.

03
Key Vocabulary

Array-field vocabulary.

Used in stat-tracking classes.

Vocabulary
  • Array field — fixed-size collection as instance variable.
  • Total — sum of all elements.
  • Max — largest element.
  • Conditional count — number of elements meeting a condition.
  • Encapsulation — array is private; methods do the work.
04
AP Exam Focus

How array-field classes are tested.

Stat-method correctness dominates.

Exam Focus
  • Loop the field. Use enhanced-for for read-only stats.
  • Cast for average. Avoid integer truncation.
  • Empty-array safety. Guard max and average.
  • Init max from scores[0]. Not 0.
05
Worked Example

Compute multiple stats.

Same field; different aggregations.

Worked Example AP-style reasoning

Setup. Scores s = new Scores(new int[]{55, 78, 92, 60, 45});

  • s.total() → 330.
  • s.max() → 92.
  • s.countAbove(70) → 2 (78 and 92).
  • s.average() → 330.0 / 5 = 66.0.
06
Common Mistakes

Stat-method pitfalls.

Cast and init errors.

Watch Out
  • No cast in average. Truncated result.
  • Init max = 0. Wrong for all-negative arrays.
  • Empty-array crash. Division by zero or get(0) on empty.
  • Wrong threshold direction. "Above" vs "at least".
07
Reference Table

Stat methods at a glance.

Common aggregations.

Stats Reference

AP Quick Reference
MethodReturnsInitial
totalint0
maxintscores[0]
countAboveint0
averagedouble0.0 on empty
08
Practice Tip

How to master stat methods.

One method per stat; guard the edges.

Practice Strategy
  • MCQ Practice — verify each method's initial value and edge-case handling.
  • Java Lab — write Scores class with multiple stat methods. Test on empty input.
  • FRQ Practice — each stat gets its own short method; chain them in the test code.
09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

FRQ Practice 30 min 19 marks Pending

AP CSA Unit 13 Topic 13 Statistics over an Array Field FRQ Practice

AP-style topic practice assessment

Start