//VARIABLES// float white=255, black=0; //STRINGS FOR ARRAY// String names[]= { "Richard", "Michael", "Steven", "James", "Andrew", "Jimmy", "David", "Leonard", "Max", "Adam"}; String columns[]= { "NAMES", "AGE", "WEIGHT", "HEIGHT", "BMI"}; int age[]= {19, 23, 95, 58, 124, 31, 21, 37, 40, 8, 14}; int wt[]= { 130, 156, 187, 109, 210, 148, 115, 123, 203, 99}; int ht[]= { 66, 72, 78, 51, 60, 70, 80, 49, 67, 63, 66, 55, 44 }; float bmi= 0; int many= names.length; void setup() { smooth(); size(800,600); //INTIALIZE// } void draw() { //// Next frame //// background(white); drawtable(); screentext(); info(); textSize(20); text( "The last key you pressed was " + key, 20, 50 ); textSize(12); } //NAME, DATE, OTHER TEXT// void screentext() { fill(black); textSize(13); text("Rune Hernandez",10,20); text("Project 8",10,35); textSize(25); text("Table",370,90); } //TABLE THAT WILL HOLD INFO// void drawtable() { fill (white); stroke(black); strokeWeight(3); rect (100, 100, 600, 330); //VERTICALE LINES -- ARRAY FOR NAMES// strokeWeight(2); stroke(black); int n=0; for (int y= 130; y<430; y= y+30){ fill(black); line(100, y, 700, y); textSize(15); text(""+names[n], 110, y+20); n= n+1; } //HORIZONTLE LINES -- ARRAY FOR COLUMNS// strokeWeight(2); stroke(black); int c=0; for (int x= 100; x<600; x= x+120){ line(x, 100, x, 430); textSize(15); text(""+columns[c], x+20, 120); c= c+1; } } //INFORMATION ON THE CHART// void info() { //WEIGHT & HEIGHT & Height // int w=0; for (int y= 130; y<430; y= y+30){ fill(black); textSize(12); text(""+wt[w], 390, y+20); text(""+ht[w], 490, y+20); text(""+age[w], 270, y+20); w= w+1; } } void keyPressed() { //handle key event// if ( key == 'a' ) { sortby( age, many ); } if ( key == 'w' ) { sortby( wt, many ); } if ( key == 'h' ) { sortby( ht, many ); } if ( key == 'n' ) { sortby( names, many ); } } void sortby( int[] a, int many ) { //// Sort all, using a[] as "key" //// Find greatest age, move to end. int m; int w; //// Sort (by finding max & swapping it to [m-1] for (m=many; m>1; m-- ) { w=0; //// Index of biggest for (int i=1; i a[w]) w=i; } swapall( w, m-1 ); } } void sortby( String[] s, int many ) { //// Sort all, using String array s[] as "key" //// Find greatest age, move to end. int m; int w; //// Sort (by finding max & swapping it to [m-1] for (m=many; m>1; m-- ) { w=0; //// Index of biggest for (int i=1; i s[w]) w=i; if ( s[i].compareTo(s[w]) > 0 ) w=i; //// Index of biggest, so far } swapall( w, m-1 ); } } void swapall( int j, int k ) { //// Swap all parallel arrays //// swap( names, j, k ); swap( age, j, k ); swap( wt, j, k ); swap( ht, j, k ); } void swap( int[] a, int j, int k ) { //// Swap two int elements of array a[] // a[j] gets a[k] and vise versa int temp; temp= a[j]; a [j] = a[k]; a[k]= temp; } void swap( String[] a, int j, int k ) { //// Swap two String elements of array a[] // a[j] gets a[k] and vise versa String temp; temp= a[j]; a [j] = a[k]; a[k]= temp; } void calcbmi() { bmi= 703.0 * float(wt) / pow(float(ht),float(2)); }