public class ArrayListPractice extends ArrayListPracticeBase { //All of these methods should reference a variable named carList //which is defined in the base class for this practice class. // //Do not define carList, just use it as an ArrayList // ***** 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(); Random rand = new Random(); //Generate number between MIN and MAX. int nCars = rand.nextInt(MAX_CARS - MIN_CARS + 1) + MIN_CARS; for (int i = 0; i < nCars; i++) { int nCarName = rand.nextInt(3); int nMiles = rand.nextInt(41) * 10; int nMilesPerGallon = rand.nextInt(25 - 6 + 1) + 6; Auto car = new Auto(CAR_NAMES[nCarName], nMiles, (double) nMiles / nMilesPerGallon); carList.add(car); car = null; } animate(); } // end of fillWithcars method //Start of student code ////////////////////////////////////////////// ////////////////////////////////////////////// // ***** 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 // Write your code 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 // Write your code 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 your code here: return 0; // replace this statement with your return statement } // end of findMaximumMilesDriven method // ***** 5. Student writes this 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 your code here: return 0; // replace this statement with your return statement } // end of countFound method // ***** 6. Student writes this method /** Clears the list * Instance variable carList is the ArrayList to clear */ public void clearList() { // Note: To animate the algorithm, put this method call as the // last statement in the method // animate( ); // Write your code here: } // end of clearList method // ***** 7. Student writes this method /** Remove last car from the list * Instance variable carList is the ArrayList to clear * Be sure to handle the case when the list is empty */ public void removeLast() { // Note: To animate the algorithm, put this method call as the // last statement in the method // animate( ); // Write your code here: } // end of clearList method //End of student code ////////////////////////////////////////// }