Untitled
unknown
plain_text
a year ago
2.1 kB
16
Indexable
import java.util.ArrayList;
import java.util.List;
public class Facility {
private String name;
private double pricePerHour;
private List<Reservation> reservations; // A list of reservations for this facility
// Constructor
public Facility(String name, double pricePerHour) {
this.name = name;
this.pricePerHour = pricePerHour;
this.reservations = new ArrayList<>();
}
public String getName() {
return name;
}
public double getPricePerHour() {
return pricePerHour;
}
// Method to get the list of reservations for this facility
public List<Reservation> getReservations() {
return reservations;
}
// Method to add a reservation and handle conflicts
public String addReservation(Reservation reservation) {
// Check for conflicts with existing reservations
for (Reservation existingReservation : reservations) {
if (existingReservation.conflictsWith(reservation)) {
return "The facility is not available at the selected time.";
}
}
// Add the reservation to the list
reservations.add(reservation);
return "Reservation confirmed for " + reservation.getEventName() + " on " + reservation.getDate() +
" at " + reservation.getTime() + ".";
}
// Method to display the facility's schedule
public String displaySchedule() {
StringBuilder schedule = new StringBuilder(name + " Schedule:\n");
for (Reservation reservation : reservations) {
schedule.append(reservation.toString()).append("\n");
}
return schedule.toString();
}
// Method to cancel a reservation based on ID and user
public boolean cancelReservation(int reservationId, User user) {
for (Reservation reservation : reservations) {
if (reservation.getId() == reservationId && reservation.getReservedBy().equals(user.getUsername())) {
reservations.remove(reservation);
return true;
}
}
return false;
}
}
Editor is loading...
Leave a Comment