Meeeting scheduler

mail@pastecode.io avatar
unknown
java
a month ago
3.5 kB
1
Indexable
Never
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

// Define the Meeting interface
interface Meeting {
    String getId();
    String getTitle();
    String getDescription();
    String getLocation();
    String getStartTime();
    String getEndTime();
    void setTitle(String title);
    void setDescription(String description);
    void setLocation(String location);
    void setStartTime(String startTime);
    void setEndTime(String endTime);
}

// Implement the Meeting interface
class MeetingImpl implements Meeting {
    private String id;
    private String title;
    private String description;
    private String location;
    private String startTime;
    private String endTime;

    public MeetingImpl(String title, String description, String location, String startTime, String endTime) {
        this.id = UUID.randomUUID().toString();
        this.title = title;
        this.description = description;
        this.location = location;
        this.startTime = startTime;
        this.endTime = endTime;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public String getTitle() {
        return title;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public String getLocation() {
        return location;
    }

    @Override
    public String getStartTime() {
        return startTime;
    }

    @Override
    public String getEndTime() {
        return endTime;
    }

    @Override
    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public void setLocation(String location) {
        this.location = location;
    }

    @Override
    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    @Override
    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }
}

// Define the MeetingScheduler interface
interface MeetingScheduler {
    void scheduleMeeting(Meeting meeting);
    void cancelMeeting(String meetingId);
    Meeting getMeeting(String meetingId);
}

// Implement the MeetingScheduler interface
class MeetingSchedulerImpl implements MeetingScheduler {
    private Map<String, Meeting> meetings = new HashMap<>();

    @Override
    public void scheduleMeeting(Meeting meeting) {
        meetings.put(meeting.getId(), meeting);
    }

    @Override
    public void cancelMeeting(String meetingId) {
        meetings.remove(meetingId);
    }

    @Override
    public Meeting getMeeting(String meetingId) {
        return meetings.get(meetingId);
    }
}

// Main class to demonstrate usage
public class Main {
    public static void main(String[] args) {
        MeetingScheduler scheduler = new MeetingSchedulerImpl();

        // Create a new meeting
        Meeting meeting = new MeetingImpl("Team Sync", "Discuss project updates", "Conference Room A", "2024-08-20T10:00:00", "2024-08-20T11:00:00");
        
        // Schedule the meeting
        scheduler.scheduleMeeting(meeting);
        
        // Retrieve and print meeting details
        Meeting retrievedMeeting = scheduler.getMeeting(meeting.getId());
        System.out.println("Meeting Title: " + retrievedMeeting.getTitle());

        // Cancel the meeting
        scheduler.cancelMeeting(meeting.getId());
    }
}
Leave a Comment