Advanced Meeting Scheduler System in Java: Dynamic Reservation Handling with User Attendance

The Meeting Scheduler System is designed to efficiently manage reservations for meeting rooms, considering room capacities, time intervals, and user attendance. The system supports dynamic scheduling and cancellation of meetings, ensuring effective collaboration in a shared workspace.

MeetingRoom Class:

  • Description: Represents a physical meeting room with unique identifiers and a capacity for occupants.
  • Methods:
    • reserveRoom(startTime, endTime, attendees): Reserves the room for a specified time range, checking availability and adding a reservation internally.
    • cancelReservation(startTime, endTime): Cancels a reservation for the meeting room.

Reservation Class:

  • Description: Represents a reservation for a specific time range in a meeting room, including the associated users.
  • Methods:
    • addUser(user): Adds a user to the list of users associated with the reservation.
    • removeUser(user): Removes a user from the reservation.

User Class:

  • Description: Represents an individual user in the meeting scheduler system with a unique identifier.
  • Methods: (Not explicitly defined in this example, but would typically include methods for managing the user’s schedule.)

MeetingScheduler Class:

  • Description: Manages the scheduling and cancellation of meetings, interacting with meeting rooms and users.
  • Methods:
    • reserveMeeting(room, startTime, endTime, attendees): Initiates the reservation process, checking room availability and adding the reservation to the specified room.
    • cancelMeeting(room, startTime, endTime): Cancels a reservation for the specified time range in the given room.

MeetingSchedulerSystem Class:

  • Description: Entry point for testing the meeting scheduler system, demonstrating the usage of the classes.
  • Main Method:
    • Initializes meeting rooms, a meeting scheduler, and users.
    • Demonstrates the usage of the meeting scheduler system with examples of reserving and canceling meetings.

This system ensures efficient collaboration by dynamically handling meeting reservations, allowing users to interact with the scheduler, reserve meeting rooms, and manage their schedules effectively.

import java.util.ArrayList;
import java.util.List;

class MeetingRoom {
    private String roomId;
    private int capacity;
    private List<Reservation> reservations;

    public MeetingRoom(String roomId, int capacity) {
        this.roomId = roomId;
        this.capacity = capacity;
        this.reservations = new ArrayList<>();
    }

    public String getRoomId() {
        return roomId;
    }

    public int getCapacity() {
        return capacity;
    }

    public List<Reservation> getReservations() {
        return reservations;
    }

    public void reserveRoom(String startTime, String endTime, List<User> attendees) {
        // Check if the room is available for the specified time range
        if (isRoomAvailable(startTime, endTime)) {
            // Create a new reservation
            Reservation reservation = new Reservation(startTime, endTime);
            reservation.getUsers().addAll(attendees);

            // Add the reservation to the meeting room
            reservations.add(reservation);

            // Notify users about the reservation
            System.out.println("Meeting reserved in Room " + roomId +
                    " from " + startTime + " to " + endTime + " for users: " + attendees);
        } else {
            System.out.println("Room " + roomId + " is not available for the specified time range.");
        }
    }

    public void cancelReservation(String startTime, String endTime) {
        reservations.removeIf(reservation ->
                reservation.getStartTime().equals(startTime) && reservation.getEndTime().equals(endTime));
        System.out.println("Reservation for Room " + roomId + " canceled from " + startTime + " to " + endTime);
    }

    private boolean isRoomAvailable(String startTime, String endTime) {
        // Check if the room is available for the specified time range
        for (Reservation reservation : reservations) {
            if (isOverlap(startTime, endTime, reservation.getStartTime(), reservation.getEndTime())) {
                return false; // Room is not available
            }
        }
        return true; // Room is available
    }

    private boolean isOverlap(String start1, String end1, String start2, String end2) {
        // Check if two time ranges overlap
        return !(end1.compareTo(start2) <= 0 || start1.compareTo(end2) >= 0);
    }
}

class Reservation {
    private String startTime;
    private String endTime;
    private List<User> users;

    public Reservation(String startTime, String endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
        this.users = new ArrayList<>();
    }

    public String getStartTime() {
        return startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public List<User> getUsers() {
        return users;
    }

    public void addUser(User user) {
        users.add(user);
    }

    public void removeUser(User user) {
        users.remove(user);
    }
}

class User {
    private String userId;

    public User(String userId) {
        this.userId = userId;
    }

    public String getUserId() {
        return userId;
    }
}

class MeetingScheduler {
    public void reserveMeeting(MeetingRoom room, String startTime, String endTime, List<User> attendees) {
        room.reserveRoom(startTime, endTime, attendees);
    }

    public void cancelMeeting(MeetingRoom room, String startTime, String endTime) {
        room.cancelReservation(startTime, endTime);
    }
}

public class MeetingSchedulerSystem {
    public static void main(String[] args) {
        // Initialize meeting rooms
        MeetingRoom room1 = new MeetingRoom("101", 10);
        MeetingRoom room2 = new MeetingRoom("102", 15);
        List<MeetingRoom> meetingRooms = List.of(room1, room2);

        // Create a meeting scheduler
        MeetingScheduler scheduler = new MeetingScheduler();

        // Create users
        User user1 = new User("User1");
        User user2 = new User("User2");

        // Example usage:
String date = "2024-02-09";
String startTime = "10:00 AM";
String endTime = "11:30 AM";

// Display available time slots in each room
for (MeetingRoom room : meetingRooms) {
    List<Reservation> reservations = room.getReservations();
    List<String> availableTimeSlots = new ArrayList<>();

    // Check availability for the specified time range
    boolean isAvailable = true;
    for (Reservation reservation : reservations) {
        if (endTime.compareTo(reservation.getStartTime()) <= 0 || startTime.compareTo(reservation.getEndTime()) >= 0) {
            // No overlap, so this time slot is available
            availableTimeSlots.add("Available from " + startTime + " to " + endTime);
        } else {
            // Overlap with existing reservation, mark the room as unavailable for the specified time range
            isAvailable = false;
            break;
        }
    }

    if (isAvailable) {
        System.out.println("Available time slots in Room " + room.getRoomId() + ": " + String.join(", ", availableTimeSlots));
    }
}

// Let the user choose a time slot
System.out.println("Enter the desired time slot (e.g., '10:00 AM to 11:00 AM'):");
Scanner scanner = new Scanner(System.in);
String selectedTimeSlot = scanner.nextLine();

// Find the room with the selected time slot
MeetingRoom selectedRoom = null;
for (MeetingRoom room : meetingRooms) {
    boolean isAvailable = true;
    for (Reservation reservation : room.getReservations()) {
        if (endTime.compareTo(reservation.getStartTime()) <= 0 || startTime.compareTo(reservation.getEndTime()) >= 0) {
            // No overlap, so this time slot is available
        } else {
            // Overlap with existing reservation, mark the room as unavailable for the specified time range
            isAvailable = false;
            break;
        }
    }
    if (isAvailable) {
        selectedRoom = room;
        break;
    }
}

// Reserve the room with the selected time slot
if (selectedRoom != null) {
    scheduler.reserveMeeting(selectedRoom, date, selectedTimeSlot.split(" to ")[0], selectedTimeSlot.split(" to ")[1], List.of(user1, user2));
    System.out.println("Meeting reserved successfully!");
} else {
    System.out.println("No room available for the specified time slot.");
}

Schedule a meeting

The sequence diagram to schedule a meeting should have the following actors and objects that will interact with each other:

  • Actor: Organizer
  • Objects: SchedulerCalendarMeetingRoom, and Meeting

The steps in the schedule meeting interaction are listed below:

  1. The meeting organizer schedules a meeting for some attendees at a given interval.
  2. The scheduler checks for the availability of a meeting room.
  3. If a room is available:
    1. The scheduler books the meeting room.
    2. The scheduler creates a new meeting.
    3. The scheduler updates the calendar with the new meeting.
    4. The scheduler informs the organizer that the meeting is scheduled.
    5. The scheduler sends an invite to the attendee.
Organizer Scheduler MeetingRoom Calendar Attendee sd schedule meeting scheduleMeeting(attendee, interval) roomAvailability(interval) bookRoom(interval) room booked Meeting createMeeting(room, attendees, interval) updateCalendar(meeting) calendar updated meeting scheduled sendInvite() select another interval alt [room available] [room unavailable]

You may also like...