Modify a text file: $/7515a.solar.pde
$/7515a.solar.pde
//// CST-112 FINAL EXAM: Planet class, Button class. // **** CHANGE THIS TO many=8 **** // int many=4; int numbuttons=5; Button[] b= new Button[numbuttons]; String bname[]= { "size", "moons", "hours", "distance", "quit" }; float buttonX=220, buttonY=400; Planet[] yn = new Planet[8]; String[] namelist= { "Mercury", "Venus", "Terra", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" }; int mercury=0, venus=1, earth=2, mars=3, jupiter=4, saturn=5, uranus=6, neptune=7; float[] distlist= { 0.387, 0.723, 1, 1.52, 5.20, 9.58, 19.20, 30.05, 39.48 }; // Orbital distance (AU) float[] sizelist= { 0.25, 0.95, 1, 0.45, 10, 7, 5, 5 }; // Multiple of Earth diameter. float[] spinlist= { 58.8, -244, 1, 27.4, 1.03, 0.415, 0.445, -0.720, 0.673, 6.41 }; int[] moonlist= { 0, 0, 1, 2, 67, 62, 27, 14, 5 }; // Moons boolean[] ringlist= { false, false, false, false, true, true, true, false }; void setup() { size( 640, 480 ); yn[0]= new Planet( 1, "Mercury" ); yn[0].distance= 0.387; yn[0].size= 0.25; // yn[1]= new Planet( 2, namelist[1] ); yn[1].distance= distlist[1]; yn[1].size= 0.95; // yn[2]= new Planet( 3, namelist[2] ); yn[2].moons= 1; // yn[3]= new Planet( 4, namelist[3] ); yn[3].distance= distlist[3]; yn[3].size= 0.45; yn[3].moons= 2; yn[4]= new Planet( ); yn[5]= new Planet( ); yn[6]= new Planet( ); yn[7]= new Planet( ); //// ++++ REPLACE THE ABOVE LINES WITH A LOOP & ADD SOME NEW CONSTRUCTORS.. ++++ // Force Mars red. yn[mars].r= 255; yn[mars].g = 60; yn[mars].b = 60; //// Buttons //// float x=buttonX, y=buttonY; b[0]= new Button(); b[0].x= buttonX+80; b[0].name= "size"; // More buttons: "moons", "hours", "distance", "quit" //// ++++ REPLACE THE ABOVE LINES WITH A LOOP & ADD SOME NEW CONSTRUCTORS.. ++++ } void draw() { background( 0, 0, 50 ); showall(); // Display the planets. buttons(); // Buttons // fill(255, 255, 100); text( "Sorting keys: s, m, h, d", width/3, height-25 ); /*REMOVE*/ fill( 255, 200, 200 ); /*REMOVE*/ text( " (Now, make the buttons work!)", width/3, height-10 ); // +++++ ADD YOUR CODE (to make buttons work), then remove the above lines. flag( 20, height-120 ); } void showall() { labels( 10, 40 ); float x=80, y=40; yn[0].show( x, y ); yn[1].show( x+60, y ); yn[2].show( x+120, y ); yn[3].show( x+180, y ); // Do the same for planets 4, 5, 6, 7 //// ++++ REPLACE THE ABOVE LINES WITH A LOOP & ADD YOUR NEW CODE HERE ++++ averages( x+490, 40 ); } void buttons() { float x=buttonX, y=height-60; text( "SORT BY:", x, height-60 ); // ++++++ ADD YOUR CODE HERE & REMOVE THE FOLLOWING LINES. ++++ /*REPLACE*/ b[0].show(); /*REPLACE*/ fill(0,255,0); /*REPLACE*/ text( "Display the other buttons, too!", x+150, y ); } void bambuttons() { for (int j=0; j
0) text( moons, x+20, y+next*line++ ); fill(r, g, b); // showdisc( x + 20, y+next*line++ ); } void showdisc( float xx, float yy ) { // Circle in column x, use orbit for y value. stroke( r, g, b ); float yyy= yy + + orbit*20; line( xx, yy, xx, yyy ); float diameter= (float) Math.log(10*size) * 10; ellipse( xx, yyy, diameter, diameter ); if (ring) { stroke( r, g, b ); noFill(); ellipse( xx, yyy, 1.5*diameter, 0.5*diameter ); } }// END OF showdisc() // }// END OF class Planet // //// SORT METHODS //// void sortSize( Planet[] a, int many ) { for (int m=many; m>1; --m) { // Move biggest to end, then shrink array. int w= wSize( a, m ); swap( a, m-1, w ); } } int wSize( Planet[] a, int m ) { int w=0; for (int j=1; j
= a[w].size) w=j; } return w; } void swap( Planet a[], int j, int k) { Planet tmp= a[j]; a[j]= a[k]; a[k]= tmp; } void sortMoons( Planet[] a, int many ) { for (int m=many; m>1; --m) { swap( a, m-1, wMoons( a, m ) ); // Move biggest to end, then shrink array. } } int wMoons( Planet[] a, int m ) { int w=0; for (int j=1; j
= a[w].moons) w=j; } // If this one is bigger, change w to point to it. return w; } void sortHours( Planet[] a, int many ) { for (int m=many; m>1; --m) swap( a, m-1, wHours( a, m ) ); // Move biggest to end, then shrink array. } int wHours( Planet[] a, int m ) { int w=0; for (int j=1; j
= a[w].spin) w=j; // If this one is bigger, change w to point to it. return w; } // ++++ ADD A sortDistance() method HERE ++++++