Skip to content

ArrayLists Team Teach HW #12

@eshaank1

Description

@eshaank1

2023 FRQ:

A.

public void cleanData(double lower, double upper) {
    // iterator to safely remove elements from the ArrayList
    Iterator<Double> iterator = temperatures.iterator();
    while (iterator.hasNext()) {
        double temp = iterator.next();
        if (temp < lower || temp > upper) {
            iterator.remove();
        }
    }
}

Iterates and compares each value to the upper and lower.

B.

public int longestHeatWave(double threshold) {
    int maxHeatWaveLength = 0; // The longest heatwave length
    int currentHeatWaveLength = 0; // The current heatwave length

    for (double temp : temperatures) {
        if (temp > threshold) {
            currentHeatWaveLength++;
            maxHeatWaveLength = Math.max(maxHeatWaveLength, currentHeatWaveLength);
        } else {
            currentHeatWaveLength = 0; // Reset if temperature drops below threshold
        }
    }

    return maxHeatWaveLength;
}

Iterates and updates length of streak, udates max if longer is found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions