//final exam //Anthony Harrison int ant[]= new int[20]; color bg= color (245,255,255); string lastclick; int countA; int many; Ball newball= new Ball(); Button a=new Button ("A",100,2040,40,0, color(255,223,223) ); //++ Add more buttons here void setup () { ////initialize size (640,480); // add own code here } void draw() { /// draw each frame: buttins at top values at bottom + bar chart. background(bg); fill (0,0,255); text( "Anthony Harrison", 10, 480 ); fill(0); text("Mean average: ", 500,10); text(avg, 600,10); // display array showArray (ant, ant.height); //buttons showButtons(); //show ball, if visible. if(newball.visible) { newball.move(); newball.show(); if (newball.isOver(mouseX,mouseY)) { newball.vanish(); } } // DEBUGGING: if (newball.visible) { text(newball.x, 600,170); text(newball.y, 600,180); } fillArray; } void showButtons() { //// Show the buttons. ant.show(); //++++ ADD YOUR CODE HERE. } void mousePressed() { background(200,255,90); } int whereBig(int ant[], int many) { int w=0; for (int j=1; j ant[w]) w=j; } return w; } void swap( int ant[], int i, int j) { int tmp; tmp=ant[i]; ant[i]=a[j]; ant[j]=tmp; } //// Check which button was clicked /* When a button is "clicked", perform the task described below: A: Change the background color, alternating between light-green and light-blue. B: Find the largest and smallest values in the array, and swap them. C: Replace each array element with random value (0-100) and recalculate the mean average. D: Change the array (and recalculate average): Double all values that are less than the mean average. Subtract 50 from all values that are greater than the mean average E: Change the array (and recalculate average): Add ten to all odd values in the array; Divide all odd values by three. F: Create a new ball (30 pixels diameter, randomly colored) at a random height on the left side. Ball moves diagonally (2 down, 3 right), "bouncing" off all edges of the window. Ball vanishes if it hits (or comes within a 50-pixel radius of) mouse position. */ void wasClicked( Button x ) { //// Record which button was clicked. lastClick= x.name; x.count++; } if (ant.isOver(mouseX,mouseY)) { wasClicked(a); countA++; //++++ ADD YOUR CODE HERE. } //++++ ADD YOUR CODE HERE. } void fillArray ( int ant[], int many) { for (int j=0; j0) text(count, x+20, y+h/2+10 ); } boolean isOver( int xx, int yy ) { //// Return true if xx,yy is over this button! if (xx < x) return false; else if (xx > x+w) return false; else if (yy < y) return false; else if (yy > y+h) return false; return true; } } class Ball { //// A ball, displayed on screen if x>0. int x,y,r=10; // Position and size of this ball. int dx=3; int dy=2; color c= color(255,0,0);; boolean visible=false; //// METHODS() //// void create() { //// Create a ball. visible= true; //++++ ADD YOUR CODE HERE ++++ x=0; y= (int) random(height); } void vanish() { //// Make the ball vanish. visible= false; } void show() { //// Show the ball, only if it is visible. if (visible) { //++++ ADD YOUR CODE HERE ++++ } } void move() { //// Move the ball. Bounce off walls. //++++ ADD YOUR CODE HERE ++++ } boolean isOver( int xx, int yy ) { //// Return true if xx,yy is over this button! //++++ ADD YOUR CODE HERE ++++ if (xx < x) return false; else if (xx > x+w) return false; else if (yy < y) return false; else if (yy> y+h) return false; background(0); return true; } } }