Comparing consecutive-temperature alarm conditions

An equipment monitor records one temperature per second. The following Processing sketch in Java mode processes the stored temperatures, in °C, once from beginning to end:


Java
int[] temperature = {74, 78, 82, 79, 65, 76, 81, 84, 87, 60, 83};

void setup() {
  int run = 0;
  int alarmCount = 0;
  int triggerTotal = 0;

  for (int i = 0; i < temperature.length; i++) {
    if (temperature[i] >= 75) {
      run++;
    } else {
      run = 0;
    }

    if (run == 3) {
      alarmCount++;
      triggerTotal += temperature[i];
    }
  }

  float meanTrigger = triggerTotal / float(alarmCount);
  println(alarmCount);
  println(meanTrigger);
}


Determine the final alarmCount and meanTrigger for this original sketch. Then determine both quantities for a modified sketch in which only if (run == 3) becomes if (run >= 3).


Treat the original and modified sketches as independent runs with all variables initialized as shown. Enter both alarm counts as exact integers and both mean trigger temperatures in °C, to one decimal place.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Processing Language Programming Questions: