Solid Principles compliance
#3 The class Guest that has the variables held before by a room has been added to the project, also some changes were made to the Project.java class in order to comply with it. The class Guest has the following structure:
public class Guest implements Serializable{
String name;
String contact;
String gender;
The attributes kept default access so the program can access them like before.
#5 The fixes to the OCP principle were made by creating an abstract class Room that has an ArrayList of Guest objects and can add up to maxCapacity int variable amount of elements. SingleRoom has a maxCapacity of 1 and DoubleRoom a max capacity of 2. Also, the code was adjusted to comply with these changes. The class Room has the following structure and method addGuest():
abstract class Room implements Serializable{
ArrayList<Guest> guests=new ArrayList<>();
int maxCapacity;
ArrayList<Food> food =new ArrayList<>();
void addGuest(Guest g) {
if(g!=null && guests.size()<maxCapacity)
guests.add(g);
else if(g!=null)
throw new NotAvailable();
}
}
#6 Added classes FoodItem and FoodList, in order to comply with Open Closed Principle of SOLID design. Now to extend the amount of items it's just needed to add them at the initiateFood method, it could also read from a file, but now it is only necessary to modify initiateFood.
static void initiateFood() {
foodList.add(new FoodItem(50,1));
foodList.add(new FoodItem(60,2));
foodList.add(new FoodItem(70,3));
foodList.add(new FoodItem(30,4));
}