public void OrderProcessingFunc() { // request = "-1"; try { // while (request.Equals("-1")) // Take the order form the queue Monitor.Enter(Mainapp.Buffer); // Acquire lock on Buffer object request = Mainapp.Buffer.getOneCell(); // Get the order in form of the string } finally { Monitor.Exit(Mainapp.Buffer); } // Release lock on Buffer object OrderClass order = Decoder.Decode(request); // Convert string to object of type OrderClass Tax = r.Next(1, 10); LocationCharge = r.Next(10, 150); if (order.getCreditCard() >= 30000 && order.getCreditCard() <= 70000) // Check whether credit card id valid { Thread.Sleep(r.Next(1, 3000)); Console.WriteLine(); Console.WriteLine("-----------------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("Order from the Dealer " + order.getSenderID() + " has been processed"); Int32 price = order.getUnitPrice() * order.getAmount(); // Calculate the final amount float final_amount = price + (float)Tax / 100 * price + LocationCharge; Console.WriteLine("Total number of cars:" + order.getAmount() + " Unit Price:" + order.getUnitPrice() + " $k" + " Tax: " + (float)Tax / 100 * price + " LocationCharge: " + LocationCharge + " Total amount:" + final_amount + " $k"); // Print the final amount and order detailss Console.WriteLine("------------------------------------------------------------------------------------------------------------------------------"); } else { Console.WriteLine("Credit card details are incorrect"); } }
// Encode function to convert object of type OrderClass to String by adding space as delimiter public static String Encode(OrderClass e) { String s = Convert.ToString(e.getSenderID()) + " " + Convert.ToString(e.getAmount()) + " " + Convert.ToString(e.getCreditCard()) + " " + Convert.ToString(e.getUnitPrice());; return(s); }