示例#1
0
        ///<summary>
        ///This function computes maximum possible sell price from
        ///garbage list. Some garbage may be disassembled into
        ///material garbages that are sellable, yet there is a
        ///disassemblement cost to pay.
        ///</summary>
        public static float ComputeMaximumSellPrice(List <Garbage> garbageList)
        {
            //  NOTE: Read more on this link https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/casting-and-type-conversions
            List <MaterialGarbage> outputgarbageList      = new List <MaterialGarbage>();
            List <float>           outputgarbageListPrice = new List <float>();

            for (int SellPrice = 0; garbageList.Count > SellPrice; SellPrice++)
            {
                if (garbageList[SellPrice] is ISellable)
                {
                    if (garbageList[SellPrice] is IDisassemblable)
                    {
                        ElectronicsGarbage output = (ElectronicsGarbage)garbageList[SellPrice];
                        outputgarbageList = output.Disassemble();
                        float DisassemblePrice = 0.0f;
                        float price            = 0.0f;
                        for (int SumSell = 0; outputgarbageList.Count > SumSell; SumSell++)
                        {
                            price            = outputgarbageList[SumSell].GetSellPrice();
                            DisassemblePrice = DisassemblePrice + price;
                        }
                        Size a = output.GetSize();

                        if (a == Size.SMALL)
                        {
                            float m     = 1.2f;
                            float Price = output.GetSellPrice() + DisassemblePrice - (m * output.GetDisassembleCost());
                            outputgarbageListPrice.Add(Price);
                        }
                        else if (a == Size.MEDIUM)
                        {
                            float m     = 1.4f;
                            float Price = output.GetSellPrice() + DisassemblePrice - (m * output.GetDisassembleCost());
                            outputgarbageListPrice.Add(Price);
                        }
                        else if (a == Size.LARGE)
                        {
                            float m     = 1.6f;
                            float Price = output.GetSellPrice() + DisassemblePrice - (m * output.GetDisassembleCost());
                            outputgarbageListPrice.Add(Price);
                        }
                    }
                    else if (garbageList[SellPrice] is GlassBottleGarbage)
                    {
                        GlassBottleGarbage output = (GlassBottleGarbage)garbageList[SellPrice];
                        float Price = output.GetSellPrice();

                        outputgarbageListPrice.Add(Price);
                    }
                    else
                    {
                        MaterialGarbage output = (MaterialGarbage)garbageList[SellPrice];
                        float           Price  = output.GetSellPrice();

                        outputgarbageListPrice.Add(Price);
                    }
                }
            }
            float MaxSellPrice = 0;

            foreach (float Max in outputgarbageListPrice)
            {
                if (Max > MaxSellPrice)
                {
                    MaxSellPrice = Max;
                }
            }
            Console.WriteLine(MaxSellPrice);
            return(MaxSellPrice);
        }
        ///<summary>
        ///This function computes maximum possible sell price from
        ///garbage list. Some garbage may be disassembled into
        ///material garbages that are sellable, yet there is a
        ///disassemblement cost to pay.
        ///</summary>
        public static float ComputeMaximumSellPrice(List <Garbage> garbageList)
        {
            List <MaterialGarbage> outputgarbageList      = new List <MaterialGarbage>();
            List <float>           outputgarbageListPrice = new List <float>();

            for (int i = 0; i < garbageList.Count; i++)
            {
                if (garbageList[i] is ISellable)
                {
                    if (garbageList[i] is IDisassemblable)
                    {
                        ElectronicsGarbage output = (ElectronicsGarbage)garbageList[i];
                        outputgarbageList = output.Disassemble();
                        float DisassemblePrice = 0.0f;
                        float price            = 0.0f;
                        for (int j = 0; j < outputgarbageList.Count; j++)
                        {
                            price            = outputgarbageList[j].GetSellPrice();
                            DisassemblePrice = DisassemblePrice + price;
                        }
                        Size a = output.GetSize();

                        if (a == Size.SMALL)
                        {
                            float m     = 1.2f;
                            float Price = output.GetSellPrice() + DisassemblePrice - (m * output.GetDisassembleCost());
                            outputgarbageListPrice.Add(Price);
                        }
                        else if (a == Size.MEDIUM)
                        {
                            float m     = 1.4f;
                            float Price = output.GetSellPrice() + DisassemblePrice - (m * output.GetDisassembleCost());
                            outputgarbageListPrice.Add(Price);
                        }
                        else if (a == Size.LARGE)
                        {
                            float m     = 1.6f;
                            float Price = output.GetSellPrice() + DisassemblePrice - (m * output.GetDisassembleCost());
                            outputgarbageListPrice.Add(Price);
                        }
                    }
                    else if (garbageList[i] is GlassBottleGarbage)
                    {
                        GlassBottleGarbage output = (GlassBottleGarbage)garbageList[i];
                        float Price = output.GetSellPrice();

                        outputgarbageListPrice.Add(Price);
                    }
                    else
                    {
                        MaterialGarbage output = (MaterialGarbage)garbageList[i];
                        float           Price  = output.GetSellPrice();

                        outputgarbageListPrice.Add(Price);
                    }
                }
            }
            float MaxSellPrice = 0;

            foreach (float Max in outputgarbageListPrice)
            {
                if (Max > MaxSellPrice)
                {
                    MaxSellPrice = Max;
                }
            }
            Console.WriteLine(MaxSellPrice);
            return(MaxSellPrice);
        }