Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need Help doing programming activity 2 chapter 9.8. Im on part 3 in the green text where it wants me to setModelValues and im

I need Help doing programming activity 2 chapter 9.8. Im on part 3 in the green text where it wants me to setModelValues and im currently stuck on what to do.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
som bis.searchforstand + are:" ); A Search Engine for Books JUMPLE 9.15 CODE IN ACTION in this activity, you will work with an ArrayList object. Specifically, you will write the code to perform the following operations: 1. Fill the ArrayList object with Auto elements. 2. Print the Auto elements contained in the ArrayList object. 3. Set the model instance variable of every Auto element in the ArrayList object to a specified model. swt.print Arnist-Book results System.out.println("The search results for For Book tempBook : results) movie within the online resources. Click on the link to start the movie, To see a step by step illustration showing how to use the ArrayList class, look for the System.out.println( tempBook.toString() ) 8,8 Programming Activity 2: Working with the ArrayList Class 4. Find the maximum number of miles of all Auto elements contained into 5. Count the number of Auto elements in the ArrayList with as Multidimensional Arrays and the ArrayList Class CHAPTER 9 576 specified model The Amwylist object you cata wa Table 9.6 provides the API for the Auto dass. org elo w 1 TABLE 9.6 Constructors and Some Methods of the Auto Class Auto Class Constructor Summary Auto) creates an Auto object with initial default values of unknown."0, and 0.0. Autol String sodel, int milesDriven, double gallonsOfGas ) creates an Austo object with the initial values of model, milesDriven, and gallonsofgas. Auto Class Method Summary Return value Method name and argument list String get Model returns the value of model int getMilesDriven() returns the value of miles Driven double getGallonsofgas) returns the value of gallonsOfGas setModel ( String model) mutator for model Auto Auto setMilesDriven(int milesDriven ) mutator for milesDriven Auto double String setGallonsofgas( double gallonsOfGas ) mutator for gallonsOfGas milesPergallon) returns the gas mileage for this Auto object toString() returns a String representation of this object equals Object obj) compares this Auto obiert to another obiert boolean The framework for this Programming Activity will animate your algorithm so that cation counting the number of Auto elements in the ArrayList object having a model you can check the accuracy of your code. For example, Figure 9.17 shows the appli- 9.8 Programming Activity 2: Working with the ArrayList Class 577 salie equal to "Ferrari" The application accesses each element in the Arrayl.ist in order, checking the model for the desired value, "Ferrari" At this point, the current Sement being accessed is a BMW and the application has found two Auto elements with the model value. "Ferrari." Instructions In this chapter's Programming Activity 2 folder in the supplied code files, you will find the source files needed to complete this activity. Copy all the files to a folder on your computer. Note that all files should be in the same folder. Open the ArrayList Controller.java source file. Searching for five asterisk (****) will position you at the sample method and the four other locations where you will add your code. We have provided the sample code for task number 1. In every task, you will fill in the code for a method that will manipulate an existing ArrayList of Auto elements. You should not instantiate the ArrayList object; we have done that for you. Example 9.16 shows the section of the ArrayList Controller source code where you will add your code. Note that for the countFound and find Maximum MilesDriven methods, we provide a dummy return statement (return 0:). We do this so that the source code will com- pile. In this way, you can write and test each method separately, using step-wise refinement. When you are ready to write the countFound and find Maximum Miles- Driven methods, just replace the dummy return statements with the appropriate return statement for that method. X ArrayList Practice Figure 9.17 Animation of the Programming Activity Yed Cound Miles 4000 Gallons 200.0 Student's current count is 2 Multidimensional Arrays and the ArrayList Class This the bencadea is the artist with hard-coded to bects The variable caruist is the Array to be filled with Auto objects public void withars) clear carlist before adding cars carlist. clearl 1/ Reset the number of Autos to O the seeded so that the animation foedback works correctly Auto.clearunbenutos(); Auto Carl-nex Autol , 0.0.0): Auto can- new Auto Ferrari", 100, 500.0): Auto Car - new Autor "Jeep", 1000, 90.0): Auto cart new Auto "Ferrari', 10, 3.0) Auto Cars - new Auto "B". 4000. 200.0): Auto cartney Autol "Ferrari". 1000. 50.0); carlist.add( cart ): animate carl): carlist.add( car ): animated card): Carlist.add car3 ): animate Car): carlist.add card): animate( card): carlist.add( cars): animated cars): carlist. ada carb ) : animate caro); W/ end of follwithars 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 statement in your for loop // animatel car): // where car is the variable name for the current Auto object Was you loop through the ArrayList object y/ write your code here: you loop through the ArrayList object m of setModelValues method 4. Student writes this method blic int countFound( String model) 98 Progetty 2 Working with you 519 List method Student write this method hender of all the elements in Carte was model the model to assion to all Music ce variable carlist is the ArrayListed Alle void setModelValues String model) Toate the algorithm, put this method call as the Pastetenent in your for 100p car is the variable name for the current litetet Finds number of times parameter model is found in the carlist Instance variable carlist is the ArrayList in which we search Note: To animate the algorithm, put this method call as the last statement in your for loop animate car): write your code here: - com Es recimum number of miles driven Instance variable carlist is the ArrayList to search the maximus miles driven by all the Auto sosects public int findMaximum lesDriven() tote: To animate the algorith, put this method call as the last statement in your for loop animatel car, maximum): where car is the variable nane for the current Auto object W and maximum is the int variable storing the current maximus W sumber of miles for all Auto elements you have already testen Was you loop through the ArrayList ohject I write your code here: return 0; // replace this statement with your return statmest / end of findMaximuntilesDriven method **** 5. Student writes this method peran model return the model to count the number of times model was found CHAPTER 9 Multidimensional Arrays and the ArrayList Class 7 animate( car, num ): 1 where car is the variable name for the current Auto object // and num is the int variable storing the current number of 11 Auto elements whose model is equal to the method's parameter W as you loop through the ArrayList object // Write your code here: return 0;// replace this statement with your return statement 7 // end of countFound method EXAMPLE 9.16 Location of Student Code in ArrayListController The framework will animate your code so that you can watch it wor happen, be sure that your for loops call the animate method. The an you send to animate are not always the same, but the location of the is always the same, that is, the last statement of your for loop. Detail for each task are included in the code. To tact uw

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago