class Room {
#name;
#calendar = []; //array of meeting objects
constructor(name) {
this.#name = name;
//CHECKS
// console.log("From Room Class,", this.#name, this.#calendar);
}
Book(start, end) {
for (let meeting of this.#calendar) {
//Check if we can book a meeting or not
if (meeting.getStartTime < end && start < meeting.getEndTime) {
return false;
}
}
const meeting = new Meeting(start, end, this);
this.#calendar.push(meeting);
//console.log("from", this.#name, this.#calendar);
return true;
}
get getName() {
return this.#name;
}
}
class Meeting {
#startTime;
#endTime;
#room = new Room();
constructor(start, end, room) {
this.#startTime = start;
this.#endTime = end;
this.#room = room;
}
get getStartTime() {
return this.#startTime;
}
get getEndTime() {
return this.#endTime;
}
}
class Scheduler {
#rooms;
constructor(rooms) {
this.#rooms = rooms;
}
book(start, end) {
for (let room of this.#rooms) {
let flag = room.Book(start, end);
if (flag === true) {
return room.getName;
}
}
return "No rooms available at given time";
}
}
const room1 = new Room("Atlas");
const room2 = new Room("Vienna");
const room3 = new Room("Oscorp");
const rooms = [];
rooms.push(room1);
rooms.push(room2);
rooms.push(room3);
//console.log(rooms);
const scheduler = new Scheduler(rooms);
console.log(scheduler.book(2, 5));
console.log(scheduler.book(6, 8));
console.log(scheduler.book(4, 8));
console.log(scheduler.book(3, 6));
console.log(scheduler.book(7, 8));
console.log(scheduler.book(6, 9));