/**
 * Utility class for detecting duplicate names among Named objects.
 */
public class FindDuplicate {
    /**
     * Checks whether any two elements in the array share the same name.
     *
     * @param arr an array of Named objects to search for duplicates
     * @return true if at least two elements have equal names, false otherwise
     */
    public static boolean hasDuplicate(Named[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i].getName().equals(arr[j].getName())) {
                    return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Named[] students = {
            new Student("Alice", 1),
            new Student("Bob", 2),
            new Student("Alice", 3)
        };
        System.out.println(hasDuplicate(students));   

        Named[] employees = {
            new Employee("Carol", "Engineering"),
            new Employee("Dave", "Marketing")
        };

        System.out.println(hasDuplicate(employees));  
    }
}
