Beispiel #1
0
 public void S_MakeTransaction(SupplierB supplierB, double cost)
 {
     supplierB.S_Wallet.MakeTransaction(supplierB.S_Wallet, cost);
 }
Beispiel #2
0
        public void BuyRawMaterialas(Factory factory)
        {
            // Values needed for the scenario
            Random random = new Random();
            int    choice = 0;

            List <IRawMaterialsOffer> listOfRawMaterialsOffer = new List <IRawMaterialsOffer>();


            SupplierA supplierA = new SupplierA(random);

            listOfRawMaterialsOffer.Add(supplierA.GiveΟfferRawMaterials(supplierA, random));

            SupplierB supplierB = new SupplierB(random);

            listOfRawMaterialsOffer.Add(supplierB.GiveΟfferRawMaterials(supplierB, random));

            SupplierC supplierC = new SupplierC(random);

            listOfRawMaterialsOffer.Add(supplierC.GiveΟfferRawMaterials(supplierC, random));

            Console.WriteLine("Choose Which Offer you want:");
            choice = int.Parse(Console.ReadLine());

            switch (choice)
            {
            case 1:
                try
                {
                    foreach (IRawMaterialsOffer rawMaterialsOffer in listOfRawMaterialsOffer)
                    {
                        // Using Interface we take only the type of offer we want
                        if (rawMaterialsOffer is RawMaterialsOfferA rawMaterialsOfferA)
                        {
                            factory.F_MaterialsKg += rawMaterialsOfferA.QuantityKg;
                            factory.F_Wallet.MakeTransaction(factory.F_Wallet, (-rawMaterialsOfferA.PricePerKg));

                            // Check if there is a storage capacity to shelf the chocolate we asked from shop storage, if there is not enough then we will transfer only as many for as many we can shelf
                            if (rawMaterialsOfferA.QuantityKg > maxStorageRawMaterials && F_MaterialsKg > maxStorageRawMaterials)
                            {
                                factory.F_MaterialsKg = maxStorageRawMaterials;
                                Console.WriteLine("There is no other space to store Raw Materials");
                                throw new CustomException($"{maxStorageRawMaterials - rawMaterialsOfferA.QuantityKg:N0} Raw Materials was wastfully thrown");
                            }

                            // Supplier Changes
                            supplierA.S_MakeTransaction(supplierA, rawMaterialsOfferA.PricePerKg);

                            // If there is no check trigger then this will be printed
                            Console.WriteLine($"{rawMaterialsOfferA.QuantityKg:N0} kg of Raw materials was Succesfully stored in the Factory");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                break;

            case 2:
                try
                {
                    foreach (IRawMaterialsOffer rawMaterialsOffer in listOfRawMaterialsOffer)
                    {
                        // Using Interface we take only the type of offer we want
                        if (rawMaterialsOffer is RawMaterialsOfferB rawMaterialsOfferB)
                        {
                            factory.F_MaterialsKg += rawMaterialsOfferB.QuantityKg;
                            F_Wallet.MakeTransaction(F_Wallet, (-rawMaterialsOfferB.PricePerKg));

                            // Check if there is a storage capacity to shelf the chocolate we asked from shop storage, if there is not enough then we will transfer only as many for as many we can shelf
                            if (rawMaterialsOfferB.QuantityKg > maxStorageRawMaterials && F_MaterialsKg > maxStorageRawMaterials)
                            {
                                factory.F_MaterialsKg = maxStorageRawMaterials;
                                Console.WriteLine("There is no other space to store Raw Materials");
                                throw new CustomException($"{maxStorageRawMaterials - rawMaterialsOfferB.QuantityKg:N0} Raw Materials was wastfully thrown");
                            }

                            // Supplier Changes
                            supplierA.S_MakeTransaction(supplierA, rawMaterialsOfferB.PricePerKg);

                            // If there is no check trigger then this will be printed
                            Console.WriteLine($"{rawMaterialsOfferB.QuantityKg:N0} kg of Raw materials was Succesfully stored in the Factory");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                break;

            case 3:
                try
                {
                    foreach (IRawMaterialsOffer rawMaterialsOffer in listOfRawMaterialsOffer)
                    {
                        // Using Interface we take only the type of offer we want
                        if (rawMaterialsOffer is RawMaterialsOfferC rawMaterialsOfferC)
                        {
                            factory.F_MaterialsKg += rawMaterialsOfferC.QuantityKg;
                            F_Wallet.MakeTransaction(F_Wallet, (-rawMaterialsOfferC.PricePerKg));

                            // Check if there is a storage capacity to shelf the chocolate we asked from shop storage, if there is not enough then we will transfer only as many for as many we can shelf
                            if (rawMaterialsOfferC.QuantityKg > maxStorageRawMaterials && F_MaterialsKg > maxStorageRawMaterials)
                            {
                                factory.F_MaterialsKg = maxStorageRawMaterials;
                                Console.WriteLine("There is no other space to store Raw Materials");
                                throw new CustomException($"{maxStorageRawMaterials - rawMaterialsOfferC.QuantityKg:N0} Raw Materials was wastfully thrown");
                            }

                            // Supplier Changes
                            supplierA.S_MakeTransaction(supplierA, rawMaterialsOfferC.PricePerKg);

                            // If there is no check trigger then this will be printed
                            Console.WriteLine($"{rawMaterialsOfferC.QuantityKg:N0} kg of Raw materialsl was Succesfully stored in the Factory");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                break;

            default:
                Console.WriteLine("The AI will chose randomly an Offer");
                choice = random.Next(1, 4);
                break;
            }
        }