Schedule is #4 from the from the 2025 AP Computer Science A Course Description sample problems.

2025 AP CS A Course Description

The sample free response start on PDF page 168 (labeled page 161 at the bottom right).

columnWithFewest method

private int countInCol(String target, int col)
{
    int count = 0;

    for(int r = 0; r < sched.length; r++)
        if(sched[r][col].getStatus().equals(target))
            count++;

    return count;
}

public int columnWithFewest(String target)
{
    int colWithFewest = 0;

    for(int c = 1; c < sched[0].length; c++)
        if(countInCol(target, c) < countInCol(target, colWithFewest))
            colWithFewest = c;

    return colWithFewest;
}

This solution uses a helper method countInCol to count the number of appointments in given column that match a given target status. The helper method makes columnWithFewest easier to write.

This is a variation of Finding the min or max. colWithFewest starts at 0 because that is the index of the first column that might contain the fewest appointments with the given target status.

Storing both the column index and the number of appointments in the column with the fewest would result in slightly more efficient code. The solution above favors code that is easier to read and less likely to contain an error (since it doesn’t have to ensure that two variables remain in sync).

Java files with test code

ScheduleTester.java includes JUnit 5 test code with the examples from the problem. See Running JUnit 5 tests.

Appointment.java
Schedule.java
ScheduleTester.java

2025 AP CS A Course Description Free Response Solutions

Help & comments

Get help from AP CS Tutor Brandon Horn

See an error? Question? Please comment below.

Comment on Schedule free response answer