예제 #1
0
        /// <summary>
        /// Main Method for starting the application
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.SetBufferSize(200, 3000);
            Console.WriteLine("Welcome to Cardinal Hotel Booking System!!!");
            Console.WriteLine();
            Console.WriteLine("We hae follwoing hotels with price(per room) and No. of rooms available!!!");
            Console.WriteLine();
            Console.WriteLine("HotelSupplier1 with {1} Rooms at a price of ${0} per room.", HotelSupplier.getRoomPrice("HotelSupplier1"), HotelSupplier.getRoomsAvailable("HotelSupplier1"));
            Console.WriteLine("HotelSupplier2 with {1} Rooms at a price of ${0} per room.", HotelSupplier.getRoomPrice("HotelSupplier2"), HotelSupplier.getRoomsAvailable("HotelSupplier2"));
            Console.WriteLine("HotelSupplier3 with {1} Rooms at a price of ${0} per room.", HotelSupplier.getRoomPrice("HotelSupplier3"), HotelSupplier.getRoomsAvailable("HotelSupplier3"));
            Console.WriteLine();
            Console.WriteLine("Following are the Credit Card No.s for the respective Travel Agencies: ");
            Console.WriteLine();

            //Bank Service Operations .. Applying for New Credit Card
            String Card1 = BankService.generatecardno("TravelAgency1");
            String Card2 = BankService.generatecardno("TravelAgency2");
            String Card3 = BankService.generatecardno("TravelAgency3");
            String Card4 = BankService.generatecardno("TravelAgency4");
            String Card5 = BankService.generatecardno("TravelAgency5");

            Console.WriteLine("Credit Card Number for TravelAgency1: " + Card1);
            Console.WriteLine("Credit Card Number for TravelAgency2: " + Card2);
            Console.WriteLine("Credit Card Number for TravelAgency3: " + Card3);
            Console.WriteLine("Credit Card Number for TravelAgency4: " + Card4);
            Console.WriteLine("Credit Card Number for TravelAgency5: " + Card5);

            Console.WriteLine();
            //Getting the Input for Credit Card from respective Travel Agencies
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Type in the Credit for TravelAgency{0}: ", i + 1);
                String CardNum = Console.ReadLine();
                while (CardNum.Length != 8)
                {
                    Console.WriteLine("Invalid Credit Card format!! (Hint: Exaclty 8 characters>");
                    CardNum = Console.ReadLine();
                }
                TravelAgency.CreditCards[i] = BankService.EncryptCardNo(CardNum);
            }

            Console.WriteLine();
            Console.WriteLine("Thank You For Entering the Card Details !!!");
            Console.WriteLine();
            Console.WriteLine("<Hint: For Verfiying 'Rooms Full' Conditions specify the no. of events in the range of 25 plus..>");
            Console.WriteLine();
            Console.WriteLine("Do you want to Enter the No. of PriceCut Event to happen for Each Hotel Supplier??");
            Console.WriteLine("<Default is 5-10 per Supplier depending on the lowprice or highprice>(Y/N): ");

            String option = Console.ReadLine();

            if (option.ToUpper().Equals("Y"))
            {
                //Option to modify the no of event proabilities
                Console.WriteLine("Enter the No. of Price Cut Events: ");
                NoOfPriceCuts = Convert.ToInt32(Console.ReadLine());
                while (NoOfPriceCuts <= 0)
                {
                    Console.WriteLine("Enter a minimum value of 1 or more...");
                    NoOfPriceCuts = Convert.ToInt32(Console.ReadLine());
                }
            }
            Console.WriteLine();
            Console.WriteLine("Starting to Execute Events....");
            Thread.Sleep(2000);

            Thread h1 = new Thread(new ThreadStart(HotelSupplier1.InvokePricingModel));
            Thread h2 = new Thread(new ThreadStart(HotelSupplier2.InvokePricingModel));
            Thread h3 = new Thread(new ThreadStart(HotelSupplier3.InvokePricingModel));

            h1.Name = "HotelSupplier1";
            h2.Name = "HotelSupplier2";
            h3.Name = "HotelSupplier3";
            h1.Start();
            h2.Start();
            h3.Start();

            //Travel Agency Subscribing to PriceCut Event of Hotel Supplier
            HotelSupplier.priceCut += new priceCutEvent(TravelAgent.RoomsPriceCut);

            Console.Read();
        }
예제 #2
0
        /// <summary>
        /// Once the Hotel Supplier Receives the Order process order is called for processing the order
        /// and sends back the result to the travel agency
        /// </summary>
        public void processOrder()
        {
            while (OrderProcessingQueue.Count != 0)
            {
                String result = "";
                try
                {
                    OrderClass currentOrder = OrderProcessingQueue.Dequeue();

                    if (currentOrder.getReceiverID().Equals("HotelSupplier1"))
                    {
                        int roomsRequired = currentOrder.getNoOfRooms();
                        if (roomsRequired <= H1RoomCount)
                        {
                            //Total Cost Inclusive of 15 Percent Tax + 2 Percent Location Charges
                            double amount = (roomsRequired * H1RoomPrice) + ((roomsRequired * H1RoomPrice) * 0.15) + ((roomsRequired * H1RoomPrice) * 0.02);
                            if (BankService.verifyaccount(currentOrder.getSenderID(), currentOrder.getCardNo()))
                            {
                                H1RoomCount = H1RoomCount - roomsRequired;
                                result      = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result      = result + "Required No. of rooms are booked by " + currentOrder.getSenderID() + " at " + currentOrder.getReceiverID() + ": " + currentOrder.getNoOfRooms() + " Rooms |";
                                result      = result + "Total Cost of Booking (including taxes+location charges): $" + amount + " |";
                                result      = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                            else
                            {
                                result = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result = "Invalid Credit Card Number for: " + currentOrder.getSenderID() + "|";
                                result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                        }
                        else
                        {
                            result = "Sorry HotelSupplier1 Rooms are full.. Not Enough rooms Available!!! |" + "Order from " + currentOrder.getSenderID() + " could not be processed. |";
                            result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                        }
                    }

                    else if (currentOrder.getReceiverID().Equals("HotelSupplier2"))
                    {
                        int roomsRequired = currentOrder.getNoOfRooms();
                        if (roomsRequired <= H2RoomCount)
                        {
                            //Total Cost Inclusive of 17 Percent Tax + 3 Percent Location Charges
                            double amount = (roomsRequired * H2RoomPrice) + ((roomsRequired * H2RoomPrice) * 0.17) + ((roomsRequired * H2RoomPrice) * 0.03);
                            if (BankService.verifyaccount(currentOrder.getSenderID(), currentOrder.getCardNo()))
                            {
                                H2RoomCount = H2RoomCount - roomsRequired;
                                result      = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + " :|";
                                result      = result + "Required No. of rooms are booked by " + currentOrder.getSenderID() + " at " + currentOrder.getReceiverID() + ": " + currentOrder.getNoOfRooms() + " Rooms |";
                                result      = result + "Total Cost of Booking (including taxes+location charges): $" + amount + " |";
                                result      = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                            else
                            {
                                result = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result = "Invalid Credit Card Number for: " + currentOrder.getSenderID() + "|";
                                result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                        }
                        else
                        {
                            result = "Sorry HotelSupplier2 Rooms are full.. Not Enough rooms Available!!! |" + "Order from " + currentOrder.getSenderID() + " could not be processed. |";
                            result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                        }
                    }

                    else if (currentOrder.getReceiverID().Equals("HotelSupplier3"))
                    {
                        int roomsRequired = currentOrder.getNoOfRooms();
                        if (roomsRequired <= H3RoomCount)
                        {
                            //Total Cost Inclusive of 14 Percent Tax + 4 percent Location Charges
                            double amount = (roomsRequired * H3RoomPrice) + ((roomsRequired * H3RoomPrice) * 0.14) + ((roomsRequired * H3RoomPrice) * 0.04);
                            if (BankService.verifyaccount(currentOrder.getSenderID(), currentOrder.getCardNo()))
                            {
                                H3RoomCount = H3RoomCount - roomsRequired;
                                result      = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result      = result + "Required No. of rooms are booked by " + currentOrder.getSenderID() + " at " + currentOrder.getReceiverID() + ": " + currentOrder.getNoOfRooms() + " Rooms |";
                                result      = result + "Total Cost of Booking (including taxes+location charges): $" + amount + " |";
                                result      = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                            else
                            {
                                result = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result = "Invalid Credit Card Number for: " + currentOrder.getSenderID() + "|";
                                result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                        }
                        else
                        {
                            result = "Sorry HotelSupplier3 Rooms are full.. Not Enough rooms Available!!! |" + "Order from " + currentOrder.getSenderID() + " could not be processed. |";
                            result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                        }
                    }
                    //Sends back the order to Travel Agency using a separate buffer cell
                    if (Monitor.TryEnter(CardinalMain.n4))
                    {
                        try
                        {
                            CardinalMain.n4.setOneCell(result);//Order Status Sent to Travel Agency
                        }
                        finally
                        {
                            result = "";
                            Monitor.Exit(CardinalMain.n4);
                        }
                    }
                }
                finally
                {
                }
            }
        }