//// Project #3 String title= "Project 3: array of integers"; String author= "Your Name"; int many= 20; int[] z = new int[many]; float[] d = new float[many]; float total=0, avg=0, variance=0, sigma=0; int xnum=100, xvar=180, xhelp=300, xbut=500, y0=50; void setup() { size( 640, 480 ); // Construct the buttons. /* +++++ */ /* +++++ ADD YOUR CODE HERE ++++ */ background(255); /* +++++ AND REMOVE THESE LINES ++++ */ } void draw() { background( 150,250,200 ); //// Title, etc. //// fill( 100, 0, 0 ); textSize(24); text( title, width/3, 20 ); textSize(12); text( author, width-100, height-20 ); // showAll(); help(); textSize(20); fill(0,0,255); String s="BUTTONS"; float x=xbut, y=y0+40; text( s, x, y0 ); // Display the buttons. /* ++++ */ /* ++++++++ ADD YOUR CODE HERE ++++ */ /* ++++ */ /* ++++++++ AND REMOVE THESE LINES ++++ */ /* ++++ */ /* ++++ */ fill(255,0,255); /* ++++ */ s=s+"?"; /* ++++ */ y+=40; text(s, x, y ); /* ++++ */ y+=40; text(s, x, y ); /* ++++ */ y+=40; text(s, x, y ); /* ++++ */ y+=40; text(s, x, y ); } void show( int a[], int m) { int x=xnum, y=y0+25, next=18; textSize(16); // Display the numbers. for (int j=0; j a[w]) w=j; } return w; } void big( int a[], int m ) { // Move the biggest number to the end of the array. int w= wherebig( a, m ); swap( a, w, m-1 ); // (Swap array elements, to keep all of the numbers.) } void small( int a[], int m ) { // Move the smallest number to the beginning of the array /* +++++ */ /* +++++ ADD YOUR CODE HERE ++++ */ background(0); /* +++++ AND REMOVE THESE LINES ++++ */ } int wheresmall( int[] a, int m ) { int w=0; for( int j=1; j1; m--) { int w= wherebig( q, m ); swap( q, w, m-1 ); } } void swap( int p[], int a, int b ) { //// exchange p[a] with p[b] int tmp= p[a]; p[a]= p[b]; p[b]= tmp; } void mousePressed() { // Check the buttons. /* +++++ */ /* +++++ ADD YOUR CODE HERE ++++ */ background(255);/* +++++ AND REMOVE THESE LINES ++++ */ } void keyPressed() { if (key == 'q') exit(); else if (key == 'r') reset( z, many ); else if (key == 'z') zero( z, many ); else if (key == 't') calc0( z, many ); else if (key == 'a') calc1( z, many ); else if (key == 'v') { calc0( z, many ); calc1( z, many ); calc2( z, many ); } else if (key == 'w') { reset( z, many ); calc0( z, many ); calc1( z, many ); calc2( z, many ); } // else if (key == 'b') big( z, many ); else if (key == 's') small( z, many ); else if (key == 'o') order( z, many ); // //// ++++ THESE ARE NOT YET IMPLEMENTED ++++ //// else if (key == 'n') next( z, many ); else if (key == '+') next( z, many ); else if (key == 'p') previous( z, many ); else if (key == '-') previous( z, many ); else if (key == 'd') dbl( z, many ); else if (key == 'h') half( z, many ); } void help() { fill( 0, 100, 0 ); String sub= "Press key with \nfirst letter of function"; textSize(12); text( sub, xhelp-10, y0-5); String s=""; s += "\n z fill array with zeroes"; s += "\n r random fill"; s += "\n t calculate total (*)"; s += "\n a calculate avg (*)"; s += "\n v calculate sigma (*)"; s += "\n w reset & calc"; s += "\n"; s += "\n b big to bottom"; s += "\n s small to top (*)"; s += "\n o order"; s += "\n"; s += "\n n next: +1"; s += "\n p previous: -1 (*)"; s += "\n d double (*)"; s += "\n h half (*)"; s += "\n q quit"; s += "\n (* not implemented)"; textSize(12); text( s, xhelp, y0+20 ); }