ACSA Exam Prep
← All free-response questions
Question 3 · Data Analysis with ArrayList · 5 points

Temperature Log

A science class logs one temperature reading per day. Each reading is a Reading object, stored in order by day.

public class Reading
{
    /** Returns the day number of this reading */
    public int getDay()
    { /* implementation not shown */ }

    /** Returns the temperature of this reading */
    public double getTemp()
    { /* implementation not shown */ }

    // There may be instance variables, constructors,
    // and methods that are not shown.
}

public class TempLog
{
    /** Readings in increasing day order; size() >= 1 */
    private ArrayList<Reading> readings;

    /** Returns a list of the day numbers on which the temperature
     *  rose by more than minRise compared with the previous reading.
     */
    public ArrayList<Integer> bigRises(double minRise)
    { /* to be implemented */ }

    // There may be instance variables, constructors,
    // and methods that are not shown.
}

Your class

5 points

Write bigRises. For each reading after the first, compare its temperature with the reading just before it. If it is higher by more than minRise, add that reading's day number to the list. Return the list (empty if there are none). Don't change readings.

Suppose readings holds (day, temp): (1, 60.0), (2, 64.5), (3, 63.0), (5, 70.0), (6, 71.0).

bigRises(4.0) returns [2, 5]. bigRises(10.0) returns [].

Tab inserts spaces. Drafts save as you type.
Self-score
0 / 5