Click to enlarge. |
|
Create an integer array named "z"
Display the contents of the array, Also display sum total & mean average When a button or key is pressed
|
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
Each function should accept two arguments:
|
Here is an example of a function that displays an array:
This function returns the sum of the elements:
|
These functions are called
| Action | Key | Button | ||||||
|---|---|---|---|---|---|---|---|---|
|
void reset( int a[], int m )
// Fill the array with random values // from zero to 999. | r | RESET | ||||||
|
void calc( int a[], int m )
// Calculate new total and average. | c | CALC | ||||||
|
void next( int a[], int m )
// Increase each of the numbers by one. | n | NEXT | ||||||
|
void dbl( int a[], int m )
// Double each of the numbers. | d | DOUBLE | ||||||
|
void half( int a[], int m )
// Reduce each by half. | h | HALF | ||||||
|
void big( int a[], int m )
// Move biggest number to end of the array. // (Swap elements, to preserve all numbers.) | b | BIG | ||||||
|
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!) | o | ORDER | ||||||
|
void var( int a[], int m )
// For extra credit, compute the variance and standard-deviation. | v | SIGMA | ||||||
|
NOTE:
Do not use global values in these functions;
| ||||||||
| and add mousePressed() code to call these functions when button is pressed. | |||||||