import java.util.*; import java.awt.Color; import uwcse.graphics.*; import uwcse.io.*; public class HW4 { private DataSource dataSource; /** * Constructor just constructs a DataSource to be used * for all exercises. The first argument (25) is the * number of rectangles to generate as data. The * second argument (9722321) is arbitrary. Change it * to get different random (but repeatable) data. */ public HW4() { dataSource = new DataSource( 25, 9722321 ); } /** * This routine causes exercise 'exerciseNum' to be run. * The only implementation in here now is for exercise 0, * the null exercise, written just to show the control flow. * (We don't even care exercise is asked for, we just * execute exercise 0 in this skeleton code.) */ public void runExercise( int exerciseNum ) { HashSet dataSet = null; ArrayList dataList = null; Iterator iterator = null; ArrayList resultList = null; // this call is required to alert the DataSource what exercise we're working on dataSource.startExercise( exerciseNum ); // not all of these calls are needed for each individual exercise, but they // do no harm - null is returned if the exercise doesn't use a particular kind of // collection class dataSet = dataSource.getDataSet(); dataList = dataSource.getDataList(); // exercise 11 doesn't need this, but the others do, so it's convenient to put it here resultList = new ArrayList(); // and they're off... switch ( exerciseNum ) { case 0: // the solution for exercise 0 is provided as a (trivial) example dataSource.registerResult( resultList ); break; //------------------------------------------------------------------- // Your code here... //------------------------------------------------------------------- default: // Once you've implemented exercises 1 through 11, we should never get here! dataSource.registerResult( resultList ); break; } } /** * A driver, in case you want to use it. */ public static void main(String args[]) { int cmd; int testNum; Input myInput = new Input(); HW4 mySolution = new HW4(); do { cmd = myInput.readInt( "Enter exercise number (-1 to quit, " + DataSource.NUMTESTS + " to run all tests): " ); if ( cmd == DataSource.NUMTESTS ) { for ( testNum=0; testNum < DataSource.NUMTESTS; testNum++ ) { mySolution.runExercise( testNum ); } } else if ( cmd >= 0 && cmd < DataSource.NUMTESTS ) { mySolution.runExercise( cmd ); } else { cmd = -1; } } while ( cmd >= 0 ); System.exit( 0 ); } }