// ***** 1. This method has been coded as an example /** Fills the carList with hard-coded...
Question:
// ***** 1. This method has been coded as an example /** Fills the carList with hard-coded Auto objects * The instance variable carList is the ArrayList * to be filled with Auto objects */ public void fillWithCars( ) { // clear carList before adding cars carList.clear( ); // Reset the number of Autos to 0 // This is needed so that the animation feedback works correctly Auto.clearNumberAutos( );
Auto car1 = new Auto( "BMW", 0, 0.0 ); Auto car2 = new Auto( "Ferrari", 100, 500.0 ); Auto car3 = new Auto( "Jeep", 1000, 90.0 ); Auto car4 = new Auto( "Ferrari", 10, 3.0 ); Auto car5 = new Auto( "BMW", 4000, 200.0 ); Auto car6 = new Auto( "Ferrari", 1000, 50.0 );
carList.add( car1 ); animate( car1 ); carList.add( car2 ); animate( car2 ); carList.add( car3 ); animate( car3 ); carList.add( car4 ); animate( car4 ); carList.add( car5 ); animate( car5 ); carList.add( car6 ); animate( car6 ); } // end of fillWithcars method
// ***** 2. Student writes this method /** Prints carList to console, elements are separated by a space * The instance variable carList is the ArrayList to be printed */ public void printAutoList( ) { // Note: To animate the algorithm, put this method call as the // last element in your for loop // animate( car ); // where car is the variable name for the current Auto object // as you loop through the ArrayList object // code goes here: } // end of printAutoList method
// ***** 3. Student writes this method /** Sets the model of all the elements in carList to parameter value * The instance variable carList is the ArrayList to be modified * @param model the model to assign to all Auto objects in carList */ public void setModelValues( String model ) { // Note: To animate the algorithm, put this method call as the // last statement in your for loop // animate( car ); // where car is the variable name for the current Auto object // as you loop through the ArrayList object // code goes here:
} // end of setModelValues method
// ***** 4. Student writes this method /** Finds maximum number of miles driven * Instance variable carList is the ArrayList to search * @return the maximum miles driven by all the Auto objects */ public int findMaximumMilesDriven( ) { // Note: To animate the algorithm, put this method call as the // last statement in your for loop // animate( car, maximum ); // where car is the variable name for the current Auto object // and maximum is the int variable storing the current maximum // number of miles for all Auto elements you have already tested // as you loop through the ArrayList object // Write code here: return 0; // replace this statement with your return statement } // end of findMaximumMilesDriven method
// ***** 5. student write method /** Finds number of times parameter model is found in the carList * Instance variable carList is the ArrayList in which we search * @param model the model to count * @return the number of times model was found */ public int countFound( String model ) { // Note: To animate the algorithm, put this method call as the // last statement in your for loop // animate( car, num ); // where car is the variable name for the current Auto object // and num is the int variable storing the current number of // Auto elements whose model is equal to the method's parameter // as you loop through the ArrayList object // Write code here:
return 0; // replace this statement with your return statement } // end of countFound method
public void animate( Auto car ) { AutoState as = new AutoState( car, -1 ); drawing.addAutoState( as ); }
public void animate( Auto car, int value ) { AutoState as = new AutoState( car, value ); drawing.addAutoState( as ); }
public void startAnimation( ) { AutoAnimationTimer timer = new AutoAnimationTimer( ); timer.start( ); } private class AutoAnimationTimer extends AnimationTimer { @Override public void handle( long now ) { // update screen // gc.setFill( Color.rgb( 205, 205, 205 ) ); // gc.fillRect( 0, 0, Dimensions.APP_WIDTH, Dimensions.APP_HEIGHT ); if ( drawing.doneAll( ) ) { stop( ); drawing.resetIndex( ); disableButtons( false ); drawing.resetX( ); drawing.resetY( ); } else if ( activity == 0 ) { drawing.displayCars( gc ); drawing.incrementIndex( ); drawing.addToX( 2 ); drawing.addToY( 10 ); Pause.wait( 0.3 ); } else // if( activity == 1 ) { if ( drawing.done( ) ) { stop( ); drawing.incrementIndex( ); drawing.resetX( ); Pause.wait( 0.5 ); startAnimation( ); } else // current drawing not done { drawing.drawCar( gc ); if ( activity == 2 ) drawing.drawResultForSet( gc ); if ( activity == 3 ) drawing.drawResultForCount( gc ); else if ( activity == 4 ) drawing.drawResultForMaximum( gc );
drawing.addToX( 2 ); Pause.wait( 0.02 );
} } } } }
Marketing Research An Applied Orientation
ISBN: 978-0136085430
6th edition
Authors: Naresh K Malhotra