ID: 111524104013 Page No: 1 R.M.D. Engineering College 2024-2028-ECE-A S.No: 1 Exp. Name: ArrayList Date: 2025-07-23 Aim: Write a menu-driven Java program inside a class called ArrayListMenuProgram to perform basic operations— search , delete , display , and exit —on an ArrayList of integers.The menu needs to be displayed in this format. Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Input Format : • The first line of input contains a single integer , which represents the number of elements to be added to the list. • The next lines each contain one integer — these are the elements to be inserted into the list. • After inserting the elements, the program enters a menu loop. • For each iteration of the menu: • A single integer is entered to represent the menu choice. • If the choice is (Search), the next line will contain an integer to search for in the list. • If the choice is (Delete), the next line will contain an integer to delete from the list. • If the choice is (Display), no additional input is expected. • If the choice is (Exit), the program ends. • The menu is repeated after each operation until the user selects • Invalid Option (Default Case): If the user inputs a number other than , , , or , it has to print as: " Invalid choice. Please enter a valid option ". Output Format : Based on the user's menu choice: • If is chosen: • The program expects a number to be entered. If found print, "< X > is found " If not found print, "< X > is not found " • If is chosen: • The program expects a number to be entered. If deleted print, "< X > is deleted " If not present print, "< X > does not exist " • If is chosen: • Print: " Current elements: [a, b, c, ...] " • If is chosen: • Print: " Exiting program " n n 1 2 3 4 4 1 2 3 4 1 2 3 4 ID: 111524104013 Page No: 2 R.M.D. Engineering College 2024-2028-ECE-A Note: • Refer to the sample test cases for a better understanding of the input and output formats. Source Code: q71023/ArrayListMenuProgram.java ID: 111524104013 Page No: 3 R.M.D. Engineering College 2024-2028-ECE-A package q71023; import java.util.ArrayList; import java.util.Scanner; public class ArrayListMenuProgram { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt for size System.out.print("Enter the number of elements: "); int size =scanner.nextInt(); ArrayList<Integer> list = new ArrayList<>(); // Prompt for elements System.out.println("Enter " + size + " elements:"); for (int i = 0; i < size; i++) { // Write your code here list.add(scanner.nextInt()); } while (true) { System.out.println("Menu:"); System.out.println("1. Search for an element"); System.out.println("2. Delete an element"); System.out.println("3. Display elements"); System.out.println("4. Exit"); System.out.print("Enter your choice: "); int choice = scanner.nextInt(); switch (choice) { case 1: System.out.print("Enter element to search: "); int searchElement = scanner.nextInt(); if (list.contains(searchElement)) { System.out.println(searchElement + " is found"); } else { System.out.println(searchElement + " is not found"); } break; ID: 111524104013 Page No: 4 R.M.D. Engineering College 2024-2028-ECE-A case 2: System.out.print("Enter element to delete: "); int deleteElement = scanner.nextInt(); if (list.contains(deleteElement)) { list.remove(Integer.valueOf(deleteElement)); System.out.println(deleteElement + " is deleted"); } else { System.out.println(deleteElement + " does not exist"); } break; case 3: System.out.println("Current elements: " + list); break; case 4: System.out.println("Exiting program"); scanner.close(); return; default: System.out.println("Invalid choice. Please enter a valid option"); } } } } Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter the number of elements: 10 Enter 10 elements: 1 2 ID: 111524104013 Page No: 5 R.M.D. Engineering College 2024-2028-ECE-A 3 4 5 6 7 8 9 10 Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 1 Enter element to search: 10 10 is found Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 1 Enter element to search: 12 12 is not found Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 2 Enter element to delete: 8 8 is deleted Menu: 1. Search for an element 2. Delete an element ID: 111524104013 Page No: 6 R.M.D. Engineering College 2024-2028-ECE-A 3. Display elements 4. Exit Enter your choice: 2 Enter element to delete: 12 12 does not exist Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 3 Current elements: [1, 2, 3, 4, 5, 6, 7, 9, 10] Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 6 Invalid choice. Please enter a valid option Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 4 Exiting program Test Case - 2 User Output Enter the number of elements: 5 Enter 5 elements: 1 2 3 ID: 111524104013 Page No: 7 R.M.D. Engineering College 2024-2028-ECE-A 4 5 Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 1 Enter element to search: 5 5 is found Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 1 Enter element to search: 8 8 is not found Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 2 Enter element to delete: 4 4 is deleted Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 2 Enter element to delete: 7 7 does not exist ID: 111524104013 Page No: 8 R.M.D. Engineering College 2024-2028-ECE-A Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 3 Current elements: [1, 2, 3, 5] Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 9 Invalid choice. Please enter a valid option Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 4 Exiting program ID: 111524104013 Page No: 9 R.M.D. Engineering College 2024-2028-ECE-A S.No: 2 Exp. Name: LinkedList Date: 2025-07-23 Aim: Write a menu-driven Java program inside a class called LinkedListMenuProgram to perform basic operations— search , delete , display , and exit —on a LinkedList of integers. The menu needs to be displayed in this format. Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Input Format : • The first line of input contains a single integer , which represents the number of elements to be added to the list. • The next lines each contain one integer — these are the elements to be inserted into the list. • After inserting the elements, the program enters a menu loop. • For each iteration of the menu: • A single integer is entered to represent the menu choice. • If the choice is (Search), the next line will contain an integer to search for in the list. • If the choice is (Delete), the next line will contain an integer to delete from the list. • If the choice is (Display), no additional input is expected. If the choice is (Exit), the program ends. • The menu is repeated after each operation until the user selects • Invalid Option (Default Case): If the user inputs a number other than , , , or , it has to print as: " Invalid choice. Please enter a valid option ". Output Format : Based on the user's menu choice: • If is chosen: • The program expects a number to be entered. If found print, "< X > is found " If not found print, "< X > is not found " • If is chosen: • The program expects a number to be entered. If deleted print, "< X > is deleted " If not present print, "< X > does not exist " • If is chosen: • Print: " Current elements: [a, b, c, ...] " • If is chosen: • Print: " Exiting program " n n 1 2 3 4 4 1 2 3 4 1 2 3 4 ID: 111524104013 Page No: 10 R.M.D. Engineering College 2024-2028-ECE-A Note: • Refer to the sample test cases regarding input and output formats. Source Code: q71030/LinkedListMenuProgram.java ID: 111524104013 Page No: 11 R.M.D. Engineering College 2024-2028-ECE-A package q71030; import java.util.LinkedList; import java.util.Scanner; public class LinkedListMenuProgram { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt for size System.out.print("Enter the number of elements: "); int size = scanner.nextInt(); // Write your code here for linked list LinkedList<Integer> list = new LinkedList<>(); // Prompt for elements System.out.println("Enter " + size + " elements:"); for (int i = 0; i < size; i++) { list.add(scanner.nextInt()); } while (true) { System.out.println("Menu:"); System.out.println("1. Search for an element"); System.out.println("2. Delete an element"); System.out.println("3. Display elements"); System.out.println("4. Exit"); System.out.print("Enter your choice: "); int choice = scanner.nextInt(); switch (choice) { case 1: System.out.print("Enter element to search: "); int searchElement = scanner.nextInt(); if (list.contains(searchElement)) { System.out.println(searchElement + " is found"); } else { System.out.println(searchElement + " is not found"); } break; case 2: ID: 111524104013 Page No: 12 R.M.D. Engineering College 2024-2028-ECE-A System.out.print("Enter element to delete: "); int deleteElement = scanner.nextInt(); if (list.contains(deleteElement)) { list.remove(Integer.valueOf(deleteElement)); // Removes the first occurrence of the element System.out.println(deleteElement + " is deleted"); } else { System.out.println(deleteElement + " does not exist"); } break; case 3: System.out.println("Current elements: " + list); break; case 4: System.out.println("Exiting program"); scanner.close(); return; default: System.out.println("Invalid choice. Please enter a valid option"); } } } } Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter the number of elements: 10 Enter 10 elements: 1 2 3 4 ID: 111524104013 Page No: 13 R.M.D. Engineering College 2024-2028-ECE-A 5 6 7 8 9 10 Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 1 Enter element to search: 10 10 is found Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 1 Enter element to search: 12 12 is not found Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 2 Enter element to delete: 8 8 is deleted Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: ID: 111524104013 Page No: 14 R.M.D. Engineering College 2024-2028-ECE-A 2 Enter element to delete: 12 12 does not exist Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 3 Current elements: [1, 2, 3, 4, 5, 6, 7, 9, 10] Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 6 Invalid choice. Please enter a valid option Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 4 Exiting program Test Case - 2 User Output Enter the number of elements: 5 Enter 5 elements: 1 2 3 4 5 Menu: ID: 111524104013 Page No: 15 R.M.D. Engineering College 2024-2028-ECE-A 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 1 Enter element to search: 5 5 is found Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 1 Enter element to search: 8 8 is not found Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 2 Enter element to delete: 4 4 is deleted Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 2 Enter element to delete: 7 7 does not exist Menu: 1. Search for an element 2. Delete an element ID: 111524104013 Page No: 16 R.M.D. Engineering College 2024-2028-ECE-A 3. Display elements 4. Exit Enter your choice: 3 Current elements: [1, 2, 3, 5] Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 9 Invalid choice. Please enter a valid option Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 4 Exiting program ID: 111524104013 Page No: 17 R.M.D. Engineering College 2024-2028-ECE-A S.No: 3 Exp. Name: HashSet Date: 2025-07-23 Aim: Write a menu-driven Java program inside a class called HashSetMenuProgram to perform basic operations — search , delete , display , and exit — on a HashSet of integers. The menu needs to be displayed in this format. Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Input Format : • The first line of input contains a single integer , which represents the number of elements to be added to the list. • The next lines each contain one integer — these are the elements to be inserted into the list. • After inserting the elements, the program enters a menu loop. • For each iteration of the menu: • A single integer is entered to represent the menu choice. • If the choice is (Search), the next line will contain an integer to search for in the list. • If the choice is (Delete), the next line will contain an integer to delete from the list. • If the choice is (Display), no additional input is expected. • If the choice is (Exit), the program ends. • The menu is repeated after each operation until the user selects • Invalid Option (Default Case): If the user inputs a number other than , , , or , it has to print as : " Invalid choice. Please enter a valid option ". Output Format : Based on the user's menu choice:, • If is chosen: • The program expects a number to be entered. If found print, "< X > is found " If not found print, "< X > is not found " • If is chosen: • The program expects a number to be entered. If deleted print, "< X > is deleted " If not present print, "< X > does not exist " • If is chosen: • Print: " Current elements: [a, b, c, ...] " • If is chosen: • Print: " Exiting program " Source Code: n n 1 2 3 4 4 1 2 3 4 1 2 3 4 ID: 111524104013 Page No: 18 R.M.D. Engineering College 2024-2028-ECE-A q71031/HashSetMenuProgram.java ID: 111524104013 Page No: 19 R.M.D. Engineering College 2024-2028-ECE-A package q71031; import java.util.HashSet; import java.util.Scanner; public class HashSetMenuProgram { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt for size System.out.print("Enter the number of elements: "); int size = scanner.nextInt(); // Create a HashSet HashSet<Integer> set =new HashSet<>(); // Prompt for elements System.out.println("Enter " + size + " elements:"); for (int i = 0; i < size; i++) { set.add(scanner.nextInt()); } while (true) { System.out.println("Menu:"); System.out.println("1. Search for an element"); System.out.println("2. Delete an element"); System.out.println("3. Display elements"); System.out.println("4. Exit"); System.out.print("Enter your choice: "); int choice = scanner.nextInt(); switch (choice) { case 1: System.out.print("Enter element to search: "); int searchElement = scanner.nextInt(); if (set.contains(searchElement)==true) { System.out.println(searchElement + " is found"); } else { System.out.println(searchElement + " is not found"); } break; ID: 111524104013 Page No: 20 R.M.D. Engineering College 2024-2028-ECE-A case 2: System.out.print("Enter element to delete: "); int deleteElement = scanner.nextInt(); if (set.contains(deleteElement)) { set.remove(Integer.valueOf(deleteElement)); System.out.println(deleteElement + " is deleted"); } else { System.out.println(deleteElement + " does not exist"); } break; case 3: System.out.println("Current elements: " + set); break; case 4: System.out.println("Exiting program"); scanner.close(); return; default: System.out.println("Invalid choice. Please enter a valid option"); } } } } Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter the number of elements: 10 Enter 10 elements: 1 2