Write Code Segments that Require ArrayLists and iteration.
Need Help? Check out these resources!
- Learn: Constructing an ArrayList Object
- Learn: Adding Values to an ArrayList Object
- Learn: Accessing and Removing Values from an ArrayList Object
- Learn: Changing Values in an ArrayList Object
- Learn: Analyzing an ArrayList Object
- Learn: Iterating Over an ArrayList Object
Your Turn
- Write program code to complete the provided tasks.
- Run the code in the Java Playground to see if your code generates the desired result.
- Make necessary changes until you have satisfied the tasks.
Practice 1: Daily High Temperatures
- Given the
ArrayList tempsthat contains daily high temperatures, write program code to print the all temperatures above 100. - Try the code in the Java Playground to verify your prediction.
Practice 2: Personalize Messages
- Given the
ArrayList guests, print a personalized welcome message for each attendee of a party (e.g., "Welcome, Maria!"). - Try the code in the Java Playground to verify your prediction.
Practice 3: Longest String
- Given the
ArrayList words, write code to find and print the word with the longest string. - Try the code in the Java Playground to verify your prediction.
Practice 4: Make File Name
- Given the
ArrayList filenames, write code to add.jpgto the end of each file name that doesn't already end this way. - Try the code in the Java Playground to verify your prediction.
Practice 5: Average Mileage
- Given the
ArrayList mileage, write code to calculate and print the average mileage. - Try the code in the Java Playground to verify your prediction.