PROJECT 3:   Array of integers

Click to enlarge.

Create an integer array named "z"
    containing at least twenty (20) integer values.

Display the contents of the array,

Also display sum total & mean average

When a button or key is pressed
    modify the array (as described below).

int many=20;
int[] z = new int[many];
float total, average;

Your draw() function should look something like this:

void draw( ) {
    background( 200,255,200 );
    scene();			// Show the buttons.
    display( z, many );		// Show the array.
    messages();			// Title, author, average

Everything else is done by "closed" functions that are called when a key or button is pressed.

Each function should accept two arguments:

NOTE:   Do not use global variables to refer to the array and size, in these "closed" functions.   Instead, use the arguments, as in the following examples:

Here is an example of a function that displays an array:
// Display a list of array values
void display( int[] v, int m ) {
    int x=50, y=60, spacing=15;
    textSize( 12 );
    for (int i=0; i<m; i=i+1) {
       text( v[i], x, y );
       y = y + spacing;

This function returns the sum of the elements:
// Compute the sum.
float sum( int[] w, int m ) {  
    float result=0;
    for (int j=0; j<m; ++j) {
       result += w[j];
    return result;

These functions are called

Action Key Button
void reset( int a[], int m )
    // Fill the array with random values
    // from zero to 999.
void calc( int a[], int m )
    // Calculate new total and average.
void next( int a[], int m )
    // Increase each of the numbers by one.
void dbl( int a[], int m )
    // Double each of the numbers.
void half( int a[], int m )
    // Reduce each by half.
void big( int a[], int m )
    // Move biggest number to end of the array.
    // (Swap elements, to preserve all numbers.)
void order( int a[], int m )
    // For extra credit, rearrange (sort) the entire array (in ascending order).
NOTE: Do not use the name "sort for this function. (That is a reserved word, in Processing!)
void var( int a[], int m )
    // For extra credit, compute the variance and standard-deviation.

NOTE:   Do not use global values in these functions; use the arguments.

KEYS   The keyPressed() function should have code to call a function when the key is the first letter of that function.
    r	reset()		// Replace with random values.
    c	calc()		// Calculate new sum and average.

    n	next()		// Increase each by one.
    d	dbl()		// Double each of the numbers.
    h	half()		// Reduce each by half.
    b	big()		// Move biggest to end of array.
    o	order()		// Rearrange array in ascending order. (sort)

create buttons with names for each of these,
and add mousePressed() code to call these functions when button is pressed.