Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSE445/598 Homework #2  (100 Points)

Spring 2023

Homework 2 due: Saturday, March 4th 2023, by 11:59pm (Arizona Time) 10% will be deducted if the submissions that are received within 24 hours of the given due date; Late submissions after 24 hours will NOT be accepted

Note: This is an Individual Project and NO COLLABORAION is expected. This will strictly be enforced to maintain ASU’s academic integrity policy.

Warning: This is a long programming project designed for a study load for two weeks of estimated 2*8 = 16 hours. It is challenging at both conceptual level and implementation level. You must distribute the load in the given two and half weeks. You would not have enough time to complete it if you start the project only in the last week before the project is due. Also, Make sure you submission has all the required files before submitting.

Reading: Read C# multi-threading lecture notes and examples discussed in the class including producer- consumer, chicken farm, extended chicken farm, and multi-cell buffer examples. Also, complete the producer consumer using multi-cell buffer activity before attempting this homework

Introduction

The purpose of this project is to make sure that you understand and are familiar with the concepts covered in the lectures, including distributed computing, multithreading, thread definition, creation, management, synchronization, cooperation, event-driven programming, client and server architecture, service execution model of creating a new thread for each request, the performance of parallel computing, and the impact of multi-core   processors   to   multithreading   programs   with   complex   coordination   and   cooperation. Furthermore, you are able to apply these concepts in a programming project.

Section I Preparation and Practice Exercises (No submission required)

No submission is required for this section of exercises. However, doing these exercises can help you      better understand the concepts and thus help you in quizzes, exams, as well as the assignment questions.

1.      Reading: Textbook Chapter 2.

2.      Answer the multiple choice questions in text section 2.8. Studying the material covered in these questions can help you prepare for the lecture exercises, quizzes, and the exams.

3.      Study for the questions 2 through 20 in text section 2.8. Make sure that you understand these questions and can briefly answer these questions. Study the material covered in these questions can help you prepare for the exams and understand the homework assignment.

4.      Test the programs given in questions 24 and 25 in text section 2.8. Identify the problems in the program and give correct versions of the programs.


5.      If you want solve a more challenging problem in multithreading, you can do question 26 in text section 2.8.

6.      Tutorial. To help you complete the project in Section II, you may want go through the tutorial given in the textbook chapter 2, which consists of

6.1    Read the case study in text section 2.6.3.

6.2    Test the program given in the case study. The program can be used as the starting point for your

project in Section II.

6.3    Extend the program based on the requirement in Section II.

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 plane ticket booking system that involves airline agencies (Travel agencies) and Airlines. The system consists of multiple travel agencies (clients), e.g., priceline.com, expedia.com, and cheapoair.com, where they can book blocks of air ticket reservation across multiple Airlines (servers), e.g., American, Blue Jet, and United, that supply blocks of seats to the agencies. The required architecture and the major components of the system are shown in the diagram below.

Figure 1 Architecture of a plane ticket booking system


An Operation Scenario of the hotel block booking system is outlined below:

(1)    The Airline uses a pricing model to calculate the ticket 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.

(2)    A TravelAgency evaluates the price, generates an OrderObject (See the description of the order object given below), 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.

(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 Airline receives the encoded string from the MultiCellBuffer and sends the string to the Decoder for decoding.

(7)    The Decoder sends the OrderObject to the Airline. The decoded object must contain the same values generated by the TravelAgency.

(8)    The Airline creates a new thread to process the order;

(9)    The OrderProcessingThread processes the order, e.g., checks the credit card number and calculates the amount.

(10)  The OrderProcessingThread 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. Airline1 through AirlineK* 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 PricingModel to determine the room prices. It defines a price-cut event that can emit an event and call the event handlers in the TravelAgencys if there is a price-cut according to the PricingModel. Event handler will send the new price and the Airline ID. It also receives the orders (in a string) from the MultiCellBuffer, 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 OrderProcessing class (or method) to process the order based on the current price. There is a counter p in the Airline. After p (e.g., p = 10) price cuts have been made, a Airline thread will terminate. You can assume that each Airline has unlimited number of seats available                            [15 points]

*Note 1: For this project assume that K = 2 (Two Airline, and each Airline has its own ID).

2. PricingModel: It can be a class or a method in Airline class that decides the price ofa seat. 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 seats available in the Airline in the same time period. You can use a hard-coded table of the price in each weekday. 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. OrderProcessing is a class or a method in a class on the supplier’s (airline) 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 Airline, or a number between two given numbers (e.g., between 5000 and 7000). Each OrderProcessing thread will calculate the total amount of charge, e.g., unitPrice*NoOfSeats + Tax. If the credit card is invalid, order will be declined. Tax is 5% [10 points]

4. TravelAgency1 through TravelAgencyN, each travel agency is a thread instantiated from the travel     agency class. The travel agency’s actions are event-driven. Each travel agency contains a call-back           method (event handler) for the Airlines to call when a price-cut event occurs. The travel agency will         calculate the number of seats to order, for example, based on the need and the difference between the        previous price and the current price.. 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. The Travel Agency threads  will terminate after the Airline thread has terminated                           [15 points]

5. OrderClass is a class that contains at least the following private data members:

•   senderId: the identity of the sender (Travel Agent ID), you can use thread name or thread 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 Airline;

•   amount: an integer that represents the number of seats 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 OrderObjects.    [15

points]

6. MultiCellBuffer class is used for the communication between the travel agencies (clients) and the      Airlines (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 Airlines. Each Airlines reads orders intended to that Airline only. If an Airline reads and order intended to the other Airline, order will not be read from the multi-cell buffer. [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 OrderObject.

10. Main: The Main thread will perform necessary preparation, create the buffer classes, instantiate the    objects, create threads, and start threads.                                                                                       [10 points]

Expected Output (in the console):

In the console, display the following information as system performs following operations.

•   price cuts events

•   travel agents placing and order.

•   airlines processing an order.

•   confirmation/decline after an airline processed each order.

Finally, the Summary of

o Number of price cuts events

o Number of orders from travel agents

o Numbers of orders successfully processed by airlines.

o Number of orders rejected.

Notes:

1.   It is the purchase of this course to enforce the knowledge of C# (Visual Studio). Use Visual Studio

2019 or 2022 and indicate with version you have used, so that the TA can use the same environment to grade the project.

2.   You must follow what is defined in the assignment/project document. You have flexibility to choose your implementation details if they are not specified in the document. If you are not sure on any issue, ask the instructor or the TA by posting the question in the discussion board.

3.   The program and each component of the program must be well commented.

Grading of Programming Assignment/Project

The TA will grade your program following these steps:

(1) The TA will read your program and give points based on the points allocated to each component, the readability of your code (organization of the code and comments), logic, inclusion of the required functions, and correctness of the implementations of each function.

(2) Compile the code. If it does not compile, 40% of the points given in (1) will be deducted. For example, if you are given 20 points in step (1), your points will become 12 if the program fails to compile.

(3) If the code passes the compilation, the TA will execute and test the code. If, for any reason, the program gives an incorrect output or crashes for any input, 20% of the points given in (1) will be deducted.

Please notice that the TA will not debug your program to figure out how big or how small the error is. You may lose 40% or 20% of your points for a small error such missing a comma or a space!

Late submission deduction policy:

•   10% will be deducted if the submissions that are received within 24 hours of the given due date;

•   Late submissions after 24 hours will NOT be accepted!

Where to Submission?

All submissions must be electronically submitted to the assignment folder where you downloaded the assignment paper. All files must be zipped into a single file. Make sure you submission has all the required files before submitting.