diff --git a/StudentManager.java b/StudentManager.java new file mode 100644 index 0000000..5e3e581 --- /dev/null +++ b/StudentManager.java @@ -0,0 +1,74 @@ +import java.util.HashSet; +import java.util.Iterator; +import java.util.Scanner; + +public class StudentManager { + + public static void main(String[] args) { + + HashSet students = new HashSet<>(); + Scanner sc = new Scanner(System.in); + + int choice; + + do { + System.out.println("\n===== Student Management System ====="); + System.out.println("1. Add student name"); + System.out.println("2. Display all student names"); + System.out.println("3. Remove a student name"); + System.out.println("4. Exit"); + System.out.print("Enter your choice: "); + + choice = sc.nextInt(); + sc.nextLine(); // consume newline + + switch (choice) { + + case 1: + System.out.print("Enter student name to add: "); + String name = sc.nextLine(); + + if (students.add(name)) { + System.out.println("Student added successfully."); + } else { + System.out.println("Duplicate entry! Student already exists."); + } + break; + + case 2: + System.out.println("\n--- Student List ---"); + + if (students.isEmpty()) { + System.out.println("No students in the list."); + } else { + Iterator it = students.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + } + } + break; + + case 3: + System.out.print("Enter student name to remove: "); + String removeName = sc.nextLine(); + + if (students.remove(removeName)) { + System.out.println("Student removed successfully."); + } else { + System.out.println("Student not found."); + } + break; + + case 4: + System.out.println("Exiting application. Goodbye!"); + break; + + default: + System.out.println("Invalid choice! Please try again."); + } + + } while (choice != 4); + + sc.close(); + } +}