============================================================ IT6003 - Advanced Java Programming Homework 1: Collections Framework & Generics State University of Zanzibar (SUZA) ============================================================ Total Marks: 40 Due: As announced by instructor ============================================================ INSTRUCTIONS: - Submit .java files in a ZIP named RegNo_HW1.zip - Include comments explaining your logic - You may be asked to explain your code during viva ============================================================ Problem 1: Student Registry System [10 marks] ----------------------------------------------- Create a student registration system using multiple collection types: a) Create a Student class with: regNo (String), name (String), department (String), gpa (double), courses (List). Override equals(), hashCode() (based on regNo), and toString(). Implement Comparable (sort by name). [2 marks] b) Use HashMap to store students by regNo. Implement: addStudent(), removeStudent(), findByRegNo(). Ensure no duplicate regNo. [2 marks] c) Use TreeSet to maintain students sorted by name. Print all students in alphabetical order. [1 mark] d) Use HashMap> to map each department to a set of student regNos. Implement: - addToDepartment(String dept, String regNo) - getStudentsInDept(String dept) -> List sorted by GPA [3 marks] e) Generate a report showing: - Total students per department - Highest and lowest GPA per department - Dean's list (GPA >= 3.5) sorted by GPA descending [2 marks] Problem 2: Generic Data Structures [10 marks] ------------------------------------------------ a) Implement a generic class CircularQueue with: - Constructor: CircularQueue(int capacity) - void enqueue(T item) - throws RuntimeException if full - T dequeue() - throws RuntimeException if empty - T peek() - boolean isFull(), boolean isEmpty() - int size() - String toString() showing all elements Use a generic array internally (T[] with casting). [5 marks] b) Implement a generic interface Filterable: List filter(List items, Predicate condition); List reject(List items, Predicate condition); T findFirst(List items, Predicate condition); long count(List items, Predicate condition); Create a class DataProcessor implementing Filterable. Test with List, List, List. [5 marks] Problem 3: Nested Collections Challenge [10 marks] ------------------------------------------------------ Build a University Timetable system: Data structure: Map>> Outer key: Day of week (Monday-Friday) Inner key: Time slot ("08:00-10:00", "10:00-12:00", "14:00-16:00") Value: List of course codes scheduled at that time a) Populate the timetable with at least 15 courses across the week. [2 marks] b) Implement these query methods: [8 marks] - List getCoursesOnDay(String day) - List getCoursesAtTime(String timeSlot) // across all days - boolean hasConflict(String day, String timeSlot) // more than 3 courses - String findFreeSlots(String day) // time slots with no courses - Map courseCountPerDay() // how many courses each day - String busiestDay() // day with most courses - void printFormattedTimetable() // nicely formatted table output Problem 4: Iterator Implementation [10 marks] ------------------------------------------------- a) Implement a generic class FilteredIterator that wraps an Iterator and only returns elements matching a Predicate. Implement Iterator interface (hasNext, next, remove). [5 marks] b) Implement a generic class MergedIterator that takes two sorted Iterator objects (elements implement Comparable) and iterates through both in sorted order (merge operation). [5 marks] Test both with sample data and print results. ============================================================ Viva Questions (be prepared): 1. What is the time complexity of HashMap.get() vs TreeMap.get()? 2. When would you use LinkedHashMap over HashMap? 3. Explain type erasure in generics. 4. Can you create a generic array in Java? Why or why not? ============================================================