Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help on this project as soon as possible will give thumbs up immediately for working code! Section II Project (Submission required) Purpose of this
Need help on this project as soon as possible will give thumbs up immediately for working code!
Section II Project (Submission required) Purpose of this project is to exercise the concepts learned in this chapter. It is not the purpose of this project to create realistic services and applications. We will create more realistic services and applications in the subsequent projects. In this project, you can use a console application or a simple GUI application to implement the user interface to your program. Description: Consider that you are creating a simplified hotel block booking system that involves hotel retailers (agencies and wholesalers (hotel suppliers). The system consists of multiple travel agencies (clients), e.g., hotels.com, hotwire.com, and priceline.com, where they can book blocks of hotel rooms, and multiple hotel chains (servers), e.g., Days Inn, Holiday Inn, and Hilton, that supply blocks of hotel rooms to the agencies. The required architecture and the major components of the system are shown in the diagram below. Server side Client side Main Decoder A thread is created for each order request Order Processing Thread Threads String Order Object Order Object Order Processing Thread String String TravelAgency1 String > HotelSupplier 1 OrderProcessing Thread Encoder Order Object OrderProcessing Thread TravelAgencyN Multi-cell buffer HotelSupplier String Order Processing Thread Event subscription y Order Processing Thread Event callback Figure 1 Architecture of a hotel block booking system An Operation Scenario of the hotel block booking system is outlined below: (1) The HotelSupplier uses a pricing model to calculate the room price. If the new price is lower than the previous price, it emits a (promotional) event and calls the event handlers in the travel agencies that have subscribed to the event. A TravelAgency evaluates the price, generates an Order Object (consisting of multiple values), and sends the order to the Encoder to convert the order object into a plain string. (3) The Encoder converts the object into a string. Page 2 of 5 (4) The Encoder sends the encoded string back to the caller. (5) The TravelAgency sends the encoded string to one of the free cells in the MultiCellBuffer. (6) The HotelSupplier receives the encoded string from the MultiCellBuffer and sends the string to the Decoder for decoding. The Decoder sends the Order Object to the HotelSupplier. The decoded object must contain the same values generated by the TravelAgency. (8) The HotelSupplier creates a new thread to process the order; (9) The Order ProcessingThread processes the order, e.g., checks the credit card number and calculates the amount. (10) The Order Processing Thread sends a confirmation to the travel agency and prints the order on screen) Components in the diagram are explained in details as follows, with their grades (points) allocation: 1. HotelSupplier1 through HotelSupplier * are the objects of a class on the server side: Each object has method to be started as a thread by the Main method and will perform a number of functions. It uses a Pricing Model to determine the room prices. It defines a price-cut event that can emit an event and call the event handlers in the Travel Agencys if there is a price-cut according to the PricingModel. Event handler will send the new price and the hotel supplier ID. It receives the orders (in a string) from the MultiCellBuffer. It calls the Decoder to convert the string into the order object. For each order, you can use the existing thread or start a new thread resulting in multiple threads for processing multiple orders from Order Processing class (or method) to process the order based on the current price. There is a counter p in the HotelSupplier. After p (e.g., p = 10) price cuts have been made, a Hotel Supplier thread will terminate. You can assume that each hotel supplier has unlimited number of rooms available [15 points] *Note 1: For this project assume that K= 2 (Two hotel suppliers, and each hotel supplier has its own ID). 2. Pricing Model: It can be a class or a method in Hotel Supplier class. It decides the price of rooms. It can increase price or decrease the price. You must define a mathematical model (random function is fine) to determine the price based on the order received within a given time period and the number of rooms available in the HotelSupplier in the same time period. You can use a hard-coded table of the price in each week day. However, you must make sure that your model will allow the price goes up some time and goes down some other time. [5 points] 3. Order Processing is a class or a method in a class on the supplier's side. Whenever an order needs to be processed, a new thread is instantiated from this class (or method) to process the order. It will check the validity of the credit card number. You can define your credit card format, for example, the credit card number from the travel agencies must be a number registered to the HotelSupplier, or a number between two given numbers (e.g., between 5000 and 7000). Each Order Processing thread will calculate the total amount of charge, e.g., unitPrice*NoOfRooms + Tax + LocationCharge. (10 points] 4. TravelAgency1 through TravelAgencyN, each travel agency is a thread instantiated from the same class (or the same method) in a class. The travel agency's actions are event-driven. Each travel agency contains a call-back method (event handler) for the HotelSuppliers to call when a price-cut event occurs. The travel agency will calculate the number of rooms to order, for example, based on the need and the difference between the previous price and the current price. The thread will terminate after the HotelSupplier thread has terminated. Each order is an OrderClass object. The object is sent to the Encoder for encoding. The encoded string is sent back to the travel agency. Then, the travel agency will send the order in String format to the MultiCellBuffer. Before sending the order to the MultiCellBuffer, a time stamp must be saved. When the confirmation of order completion is received, the time of the order will be calculated and saved (or printed). You can set N = 5 in your implementation. [15 points] Page 3 of 5 5. OrderClass is a class that contains at least the following private data members: senderId: the identity of the sender, you can use thread name or thread id; Intended Hotel Supplier ID cardNo: an integer that represents a credit card number: receiverID: the identity of the receiver, you can use thread name or a unique name that defined for a hotel supplier; amount: an integer that represents the number of room to order; You must use public methods to set and get the private data members. You must decide if these methods need to be synchronized. The instances created from this class are of the Order Object. [15 points] 6. MultiCellBuffer class is used for the communication between the travel agencies (clients) and the HotelSupplier (server): This class has n data cells, you can set n=3 for this project. The number of cells available must be less than the max number of travel agencies in your experiment. A setOneCell and getOneCell methods can be defined to write data into and to read data from one of the available cells. MultiCellBuffer keep orders to both hotel suppliers. Each hotel supplier reads orders intended to that hotel supplier only. [20 points] 7. Encoder is a class or a method in a class: The Encoder class will convert an OrderObject into a string. You can choose any way to encode the values into a string, as long as you can decode the string to the original order object. You can use a class or a method to implement the Encoder. [10 points] 8. Decoder is a class or a method in a class: The Decoder will convert the encoded string back into the Order Object 10. Main: The Main thread will perform necessary preparation, create the buffer classes, instantiate the objects, create threads, and start threads. [10 points) Section II Project (Submission required) Purpose of this project is to exercise the concepts learned in this chapter. It is not the purpose of this project to create realistic services and applications. We will create more realistic services and applications in the subsequent projects. In this project, you can use a console application or a simple GUI application to implement the user interface to your program. Description: Consider that you are creating a simplified hotel block booking system that involves hotel retailers (agencies and wholesalers (hotel suppliers). The system consists of multiple travel agencies (clients), e.g., hotels.com, hotwire.com, and priceline.com, where they can book blocks of hotel rooms, and multiple hotel chains (servers), e.g., Days Inn, Holiday Inn, and Hilton, that supply blocks of hotel rooms to the agencies. The required architecture and the major components of the system are shown in the diagram below. Server side Client side Main Decoder A thread is created for each order request Order Processing Thread Threads String Order Object Order Object Order Processing Thread String String TravelAgency1 String > HotelSupplier 1 OrderProcessing Thread Encoder Order Object OrderProcessing Thread TravelAgencyN Multi-cell buffer HotelSupplier String Order Processing Thread Event subscription y Order Processing Thread Event callback Figure 1 Architecture of a hotel block booking system An Operation Scenario of the hotel block booking system is outlined below: (1) The HotelSupplier uses a pricing model to calculate the room price. If the new price is lower than the previous price, it emits a (promotional) event and calls the event handlers in the travel agencies that have subscribed to the event. A TravelAgency evaluates the price, generates an Order Object (consisting of multiple values), and sends the order to the Encoder to convert the order object into a plain string. (3) The Encoder converts the object into a string. Page 2 of 5 (4) The Encoder sends the encoded string back to the caller. (5) The TravelAgency sends the encoded string to one of the free cells in the MultiCellBuffer. (6) The HotelSupplier receives the encoded string from the MultiCellBuffer and sends the string to the Decoder for decoding. The Decoder sends the Order Object to the HotelSupplier. The decoded object must contain the same values generated by the TravelAgency. (8) The HotelSupplier creates a new thread to process the order; (9) The Order ProcessingThread processes the order, e.g., checks the credit card number and calculates the amount. (10) The Order Processing Thread sends a confirmation to the travel agency and prints the order on screen) Components in the diagram are explained in details as follows, with their grades (points) allocation: 1. HotelSupplier1 through HotelSupplier * are the objects of a class on the server side: Each object has method to be started as a thread by the Main method and will perform a number of functions. It uses a Pricing Model to determine the room prices. It defines a price-cut event that can emit an event and call the event handlers in the Travel Agencys if there is a price-cut according to the PricingModel. Event handler will send the new price and the hotel supplier ID. It receives the orders (in a string) from the MultiCellBuffer. It calls the Decoder to convert the string into the order object. For each order, you can use the existing thread or start a new thread resulting in multiple threads for processing multiple orders from Order Processing class (or method) to process the order based on the current price. There is a counter p in the HotelSupplier. After p (e.g., p = 10) price cuts have been made, a Hotel Supplier thread will terminate. You can assume that each hotel supplier has unlimited number of rooms available [15 points] *Note 1: For this project assume that K= 2 (Two hotel suppliers, and each hotel supplier has its own ID). 2. Pricing Model: It can be a class or a method in Hotel Supplier class. It decides the price of rooms. It can increase price or decrease the price. You must define a mathematical model (random function is fine) to determine the price based on the order received within a given time period and the number of rooms available in the HotelSupplier in the same time period. You can use a hard-coded table of the price in each week day. However, you must make sure that your model will allow the price goes up some time and goes down some other time. [5 points] 3. Order Processing is a class or a method in a class on the supplier's side. Whenever an order needs to be processed, a new thread is instantiated from this class (or method) to process the order. It will check the validity of the credit card number. You can define your credit card format, for example, the credit card number from the travel agencies must be a number registered to the HotelSupplier, or a number between two given numbers (e.g., between 5000 and 7000). Each Order Processing thread will calculate the total amount of charge, e.g., unitPrice*NoOfRooms + Tax + LocationCharge. (10 points] 4. TravelAgency1 through TravelAgencyN, each travel agency is a thread instantiated from the same class (or the same method) in a class. The travel agency's actions are event-driven. Each travel agency contains a call-back method (event handler) for the HotelSuppliers to call when a price-cut event occurs. The travel agency will calculate the number of rooms to order, for example, based on the need and the difference between the previous price and the current price. The thread will terminate after the HotelSupplier thread has terminated. Each order is an OrderClass object. The object is sent to the Encoder for encoding. The encoded string is sent back to the travel agency. Then, the travel agency will send the order in String format to the MultiCellBuffer. Before sending the order to the MultiCellBuffer, a time stamp must be saved. When the confirmation of order completion is received, the time of the order will be calculated and saved (or printed). You can set N = 5 in your implementation. [15 points] Page 3 of 5 5. OrderClass is a class that contains at least the following private data members: senderId: the identity of the sender, you can use thread name or thread id; Intended Hotel Supplier ID cardNo: an integer that represents a credit card number: receiverID: the identity of the receiver, you can use thread name or a unique name that defined for a hotel supplier; amount: an integer that represents the number of room to order; You must use public methods to set and get the private data members. You must decide if these methods need to be synchronized. The instances created from this class are of the Order Object. [15 points] 6. MultiCellBuffer class is used for the communication between the travel agencies (clients) and the HotelSupplier (server): This class has n data cells, you can set n=3 for this project. The number of cells available must be less than the max number of travel agencies in your experiment. A setOneCell and getOneCell methods can be defined to write data into and to read data from one of the available cells. MultiCellBuffer keep orders to both hotel suppliers. Each hotel supplier reads orders intended to that hotel supplier only. [20 points] 7. Encoder is a class or a method in a class: The Encoder class will convert an OrderObject into a string. You can choose any way to encode the values into a string, as long as you can decode the string to the original order object. You can use a class or a method to implement the Encoder. [10 points] 8. Decoder is a class or a method in a class: The Decoder will convert the encoded string back into the Order Object 10. Main: The Main thread will perform necessary preparation, create the buffer classes, instantiate the objects, create threads, and start threads. [10 points)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started