Assignment Title: Java ArrayList Demonstration
File Name: PX_ArrayListDemo_lastname.java
Create a Java program that demonstrates how to use an ArrayList by storing, displaying, modifying, and analyzing a list of items.
ArrayListArrayList of String values.set().contains()No user input is required for this version.
The program should clearly show the original list, number of items, removed item, changed item, updated list, whether an item exists, and a numbered list of all items.
Start program
Import ArrayList class
Create an ArrayList of Strings called foods
Add 5 food items to the ArrayList
Print "Original food list"
Loop through the ArrayList
Print each food item
Print the total number of items in the ArrayList
Remove one item from the ArrayList
Print which item was removed
Replace one item in the ArrayList with a new item
Print what item was changed
Print "Updated food list"
Loop through the ArrayList
Print each updated food item
Check if a specific food is in the ArrayList
If it is found
Print that the item is in the list
Else
Print that the item is not in the list
Print "Numbered food list"
Loop through the ArrayList using index numbers
Print position number and food item
End program
// Program Name: PX_ArrayListDemo_lastname.java
// Author: Your Name
// Description:
// This program demonstrates how to use an ArrayList in Java.
// It adds items, displays them, removes an item, updates an item,
// checks for an item, and prints the list with numbered positions.
// Import the ArrayList class from the Java utility library
import java.util.ArrayList;
public class PX_ArrayListDemo_lastname
{
public static void main(String[] args)
{
// Create an ArrayList that will store String values
// In this example, the ArrayList will store favorite foods
ArrayList<String> foods = new ArrayList<String>();
// Add items to the ArrayList using the add() method
foods.add("Pizza");
foods.add("Tacos");
foods.add("Burgers");
foods.add("Pasta");
foods.add("Ice Cream");
//************************
//Fill in this area with missing code
//************************
// Print a blank line and closing message
System.out.println();
System.out.println("ArrayList demonstration complete.");
}
}
Original Food List: ------------------- Pizza Tacos Burgers Pasta Ice Cream Total number of food items: 5 Removed item: Burgers Changed item: Tacos was replaced with Salad Updated Food List: ------------------ Pizza Salad Pasta Ice Cream Pizza is in the list. Tacos is not in the list. Numbered Food List: ------------------- 1. Pizza 2. Salad 3. Pasta 4. Ice Cream ArrayList demonstration complete.
• Your files will be: • PX_ArrayListDemo_lastname.java (java program) • PX_ArrayListDemo_lastname.png (Screen print) • PX_ArrayListDemo_lastname.mp4 (video of you running your program) • Drop off all 3 files into google classroom.