Question

Add locking to the Hotel class. Since it is going to be accessed by multiple threads,...

Add locking to the Hotel class. Since it is going to be accessed by multiple threads, possibly simultaneously,

locking is required to ensure the data remains valid. Just lock all of the reservation information when necessary. This is a simple case, so you can either use a Lock object, or the synchronized keyword.

There is no need to use a condition, wait, await, signalAll, or notifyAll.

public enum RoomStatus {

EMPTY

NOT_EMPTY;

}

public enum PaymentStatus {

PAID,

UNPAID;

}

public enum Facility {

LIFT;

POWER_BACKUP;

HOT_WATERR;

BREAKFAST_FREE;

SWIMMING_POOL;

}

class User {

int userId;

String name;

Date dateOfBirth;

String mobNo;

String emailId;

String sex;

}

// For the room in hotel

class Hotel {

int hotelId;

String hotelName;

Information information;

// hotel contains the list of rooms

List<Room> rooms;

float rating;

Facilities facilities;

}

// a new booking is created for each booking

// done by any user

class Reservation {

int ReservationId;

int userId;

int hotelId;

// We are assuming that in a single

// booking we can book only the rooms

// of a single hotel

List<Rooms> bookedRooms;

int amount;

PaymentStatus status_of_payment;

Date bookingTime;

Duration duration;

}

class Information {

String city;

String pinCode;

String state;

String streetNo;

String landmark;

}

class Duration {

Date from;

Date to;

}

class Facilities {

List<Facility> facilitiesList;

}

In Java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public enum RoomStatus {

   EMPTY,

   NOT_EMPTY;

}

enum PaymentStatus {

   PAID,

   UNPAID;

}

enum Facility {

   LIFT,

   POWER_BACKUP,

   HOT_WATERR,

   BREAKFAST_FREE,

   SWIMMING_POOL;

}

class User {

   int userId;

   String name;

   Date dateOfBirth;

   String mobNo;

   String emailId;

   String sex;

}

// For the room in hotel

class Hotel implements Runnable{

   int hotelId;

   String hotelName;

   Information information;

// hotel contains the list of rooms

   List<Room> rooms;

   float rating;

   Facilities facilities;

   @Override
   public void run() {
       // TODO Auto-generated method stub
       Lock();
   }

   public void Lock()
{
System.out.println(Thread.currentThread().getName());
synchronized(Hotel.class)
{
System.out.println("Hotel class is locked down using Sychronized Keword.");
}
}
      
      
  
}

// a new booking is created for each booking

// done by any user

class Reservation {

   int ReservationId;

   int userId;

   int hotelId;

// We are assuming that in a single

// booking we can book only the rooms

// of a single hotel

   List<Room> bookedRooms;

   int amount;

   PaymentStatus status_of_payment;

   Date bookingTime;

   Duration duration;

}

class Information {

   String city;

   String pinCode;

   String state;

   String streetNo;

   String landmark;

}

class Duration {

   Date from;

   Date to;

}

class Facilities {

   List<Facility> facilitiesList;

}

Here Hotel class is locked using runnable interface, run() method and synchronised keyword.

Add a comment
Know the answer?
Add Answer to:
Add locking to the Hotel class. Since it is going to be accessed by multiple threads,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • There are a sotall of five classes and one enum required for this project. Over the...

    There are a sotall of five classes and one enum required for this project. Over the course of the projeet, it is important that you pay attention to how different responsibilities are separaled between the classes and how they work in coejuncticn to handle a probiem A quick list of the necessary items for this peogram are HotelManagement Class This is the driver class foe your peogram It will cntain a methed for setting up an initial hotel and the...

  • the first question java code eclipse app the second question is java fx gui caculator please...

    the first question java code eclipse app the second question is java fx gui caculator please fast 1. Create project called "YourFirstName_QUID'. Eg. Aliomar_202002345 2. Create two package Q1 and Q2. 3. Add your name and studentID as comments on the top of each Java source file you submit. Question 1. Bookings APP [80 Points-six parts] Implement the following hotel booking system. Use the following class diagram to understand the structure of the system's classes, their attributes operations (or methods),...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • I need to complete the C++ program for hotel reservation. In the main cpp you have...

    I need to complete the C++ program for hotel reservation. In the main cpp you have to display the hotel information from the hotel.txt based on customer preferences(which can be taken from the User.txt) For example, if the customer's budget is 200$, then only the hotels with prices below that amount should be displayed. Then the user has an option to choose which one to reserve for the particular time(which also can be found in the user.txt) The last two...

  • I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good...

    I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good to me but it will not run. Please help... due in 24 hr. Problem As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. Currently, there is a test...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT