01
Overview

A class that tracks data and reports min and average.

Two common statistics — minimum and average — wrapped inside a clean class with an ArrayList field.

The class stores numeric data, lets clients add values, and offers methods that report the minimum and the average. Both methods need to handle the empty-data case carefully.

On the AP exam, this pattern appears in score-tracking and sensor-monitoring FRQs.

02
Core Concept

Loop over the data once per stat.

Min finds smallest; average sums and divides.

DataSet class

public class DataSet {
    private ArrayList<Integer> data;

    public DataSet() { data = new ArrayList<>(); }

    public void add(int value) { data.add(value); }

    public int getMin() {
        if (data.size() == 0) return 0;     // empty case
        int min = data.get(0);
        for (int v : data) {
            if (v < min) min = v;
        }
        return min;
    }

    public double getAverage() {
        if (data.size() == 0) return 0.0;
        int sum = 0;
        for (int v : data) sum += v;
        return (double) sum / data.size();
    }
}

Initialization for min

Start min at the first element — never 0 (fails for all-positive data) or Integer.MAX_VALUE (still works but less natural). The empty guard handles the edge case.

03
Key Vocabulary

Min and average vocabulary.

Used in stat classes.

Vocabulary
  • Minimum — smallest element.
  • Average / mean — sum ÷ count.
  • Accumulator — running sum.
  • Empty guard — early return for no data.
  • Initialization from first element — safe for min.
04
AP Exam Focus

How min/average classes are tested.

Initialization and cast dominate.

Exam Focus
  • Init min from first element. Not 0.
  • Cast sum for average. Avoid integer division.
  • Empty case handling. Return sensible default.
  • Iterate the field. Use the class's own ArrayList.
05
Worked Example

Compute stats over a small dataset.

Min and average.

Worked Example AP-style reasoning
  • ds.add(7); ds.add(3); ds.add(9); ds.add(5);
  • getMin(): start min=7; compare 3 → min=3; 9 → no change; 5 → no change. Returns 3.
  • getAverage(): sum=24; size=4; 24.0/4 = 6.0.
06
Common Mistakes

Stat-class pitfalls.

Init and cast errors.

Watch Out
  • Init min = 0. Fails on all-positive data.
  • No cast in average. Integer truncation.
  • No empty guard. Division by zero or get(0) on empty list.
  • Forgetting to update min. Returns initial value.
07
Reference Table

Min vs average.

Side-by-side patterns.

Min & Average Reference

AP Quick Reference
StatInitial valueEmpty return
mindata.get(0)0 or per spec
sum0
averagesum / size0.0
08
Practice Tip

How to master min/average classes.

Init right; cast right; guard empty.

Practice Strategy
  • MCQ Practice — for each option, verify min init and average cast.
  • Java Lab — build DataSet with min and average. Test empty and all-negative inputs.
  • FRQ Practice — empty-case guard at top; init min from first; cast sum for average.
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 11 Complete Class with Min and Average FRQ Practice

AP-style topic practice assessment

Start