ID: 111524102006 Page No: 1 R.M.D. Engineering College 2024-2028-CSE-A S.No: 1 Exp. Name: ArrayList Date: 2025-08- 08 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: 111524102006 Page No: 2 R.M.D. Engineering College 2024-2028-CSE-A Note: • Refer to the sample test cases for a better understanding of the input and output formats. Source Code: q71023/ArrayListMenuProgram.java ID: 111524102006 Page No: 3 R.M.D. Engineering College 2024-2028-CSE-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 = ArrayList<Integer> list = // Prompt for elements System.out.println("Enter " + size + " elements:"); for (int i = 0; i < size; i++) { // Write your code here } 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(); // Write your code here ID: 111524102006 Page No: 4 R.M.D. Engineering College 2024-2028-CSE-A break; case 2: System.out.print("Enter element to delete: "); int deleteElement = scanner.nextInt(); // Write your code here break; case 3: // Write your code here break; case 4: System.out.println("Exiting program"); scanner.close(); return; default: System.out.println("Invalid choice. Please enter a valid option"); } } } } */ package q71023; import java.util.ArrayList; import java.util.Scanner; public class ArrayListMenuProgram { public static void main(String[] args) { Scanner sc = new Scanner(System.in); ArrayList<Integer> list = new ArrayList<>(); System.out.print("Enter the number of elements: "); int n = Integer.parseInt(sc.nextLine()); ID: 111524102006 Page No: 5 R.M.D. Engineering College 2024-2028-CSE-A System.out.println("Enter " + n + " elements:"); for (int i = 0; i < n; i++) { list.add(Integer.parseInt(sc.nextLine())); } 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; try { choice = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { choice = -1; } switch (choice) { case 1: System.out.print("Enter element to search: "); int searchElement = Integer.parseInt(sc.nextLine()); if (list.contains(searchElement)) { System.out.println(searchElement + " is found"); } else { System.out.println(searchElement + " is not found"); } break; case 2: System.out.print("Enter element to delete: "); int deleteElement = Integer.parseInt(sc.nextLine()); if (list.contains(deleteElement)) { list.remove(Integer.valueOf(deleteElement)); System.out.println(deleteElement + " is deleted"); } else { System.out.println(deleteElement + " does not exist"); } ID: 111524102006 Page No: 6 R.M.D. Engineering College 2024-2028-CSE-A System.out.println("Current elements: " + list); break; case 4: System.out.println("Exiting program"); 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 5 6 7 8 9 10 Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit ID: 111524102006 Page No: 7 R.M.D. Engineering College 2024-2028-CSE-A 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: 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: ID: 111524102006 Page No: 8 R.M.D. Engineering College 2024-2028-CSE-A 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: 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: ID: 111524102006 Page No: 9 R.M.D. Engineering College 2024-2028-CSE-A 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 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 ID: 111524102006 Page No: 10 R.M.D. Engineering College 2024-2028-CSE-A 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: 111524102006 Page No: 11 R.M.D. Engineering College 2024-2028-CSE-A S.No: 2 Exp. Name: LinkedList Date: 2025-08- 02 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: 111524102006 Page No: 12 R.M.D. Engineering College 2024-2028-CSE-A Note: • Refer to the sample test cases regarding input and output formats. Source Code: q71030/LinkedListMenuProgram.java ID: 111524102006 Page No: 13 R.M.D. Engineering College 2024-2028-CSE-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); System.out.print("Enter the number of elements: "); int size = scanner.nextInt(); LinkedList<Integer> list = System.out.println("Enter " + size + " elements:"); for (int i = 0; i < size; i++) { } 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: break; case 2: break; case 3: break; case 4: System.out.println("Exiting program"); scanner.close(); return; default: System.out.println("Invalid choice. Please enter a valid option"); } } } } */ package q71030; import java.util.LinkedList; ID: 111524102006 Page No: 14 R.M.D. Engineering College 2024-2028-CSE-A import java.util.Scanner; public class LinkedListMenuProgram { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Input number of elements System.out.print("Enter the number of elements: "); int n = scanner.nextInt(); // Input elements System.out.println("Enter " + n + " elements:"); LinkedList<Integer> list = new LinkedList<>(); for (int i = 0; i < n; i++) { list.add(scanner.nextInt()); } while (true) { // Display menu 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 search = scanner.nextInt(); if (list.contains(search)) { System.out.println(search + " is found"); } else { System.out.println(search + " is not found"); } break; case 2: System.out.print("Enter element to delete: "); int delete = scanner.nextInt(); if (list.remove((Integer) delete)) { System.out.println(delete + " is deleted"); } else { System.out.println(delete + " does not exist"); } ID: 111524102006 Page No: 15 R.M.D. Engineering College 2024-2028-CSE-A break; case 3: System.out.println("Current elements: " + list); break; case 4: System.out.println("Exiting program"); 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 5 6 7 8 9 10 Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: ID: 111524102006 Page No: 16 R.M.D. Engineering College 2024-2028-CSE-A 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: 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] ID: 111524102006 Page No: 17 R.M.D. Engineering College 2024-2028-CSE-A 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: 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 ID: 111524102006 Page No: 18 R.M.D. Engineering College 2024-2028-CSE-A 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 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 ID: 111524102006 Page No: 19 R.M.D. Engineering College 2024-2028-CSE-A Menu: 1. Search for an element 2. Delete an element 3. Display elements 4. Exit Enter your choice: 4 Exiting program ID: 111524102006 Page No: 20 R.M.D. Engineering College 2024-2028-CSE-A S.No: 3 Exp. Name: HashSet Date: 2025-08- 08 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