コード例 #1
0
        static void Main(string[] args)
        {
            string            pathToReadFrom  = @"F:\\test\Final Project\Furniture.txt";
            List <IFurniture> furniture       = FurnitureServices.ReadFurnitureFromFileIntoList(pathToReadFrom);
            List <Kit>        kitsOfFurniture = new List <Kit>();
            var tables = furniture.Where(item => item is Table)
                         .Select(item => (Table)item)
                         .ToList();
            var chairs = furniture.Where(item => item is Chair)
                         .Select(item => (Chair)item)
                         .ToList();

            Kit firstKitOfFurniture             = new Kit();
            FurnitureServices furnitureService1 = new FurnitureServices();

            furnitureService1.FillInKit(firstKitOfFurniture, tables, chairs);
            furnitureService1.WriteKitIntoFile(firstKitOfFurniture, furnitureService1.CreateAFileToWriteKitInto());
            Kit secondKitOfFurniture            = new Kit();
            FurnitureServices furnitureService2 = new FurnitureServices();

            furnitureService2.FillInKit(secondKitOfFurniture, tables, chairs);
            furnitureService1.WriteKitIntoFile(secondKitOfFurniture, furnitureService2.CreateAFileToWriteKitInto());
            kitsOfFurniture.Add(firstKitOfFurniture);
            kitsOfFurniture.Add(secondKitOfFurniture);

            Console.ReadKey();
        }
コード例 #2
0
ファイル: TableServices.cs プロジェクト: 7denth/Final-Project
        public void FindTable(Kit setOfFurniture, List <Table> tables)
        {
            int tableCounter = 0;

            while (tableCounter == 0)
            {
                Console.WriteLine("Now please type in a size of table you want to have in your set.");
                string sizeOfTable = FurnitureServices.GetSizeOrMaterial(FurnitureServices.sizeVerieties);

                Console.WriteLine("And we should define a material from which a table is made.");
                string materialOfTable = FurnitureServices.GetSizeOrMaterial(FurnitureServices.materialTypes);

                var expensiveTable = TableFilterBy(materialOfTable, sizeOfTable, tables)
                                     .Where(p => p.Price == TableFilterBy(materialOfTable, sizeOfTable, tables).Max(mp => mp.Price))
                                     .FirstOrDefault();

                if (expensiveTable != null)
                {
                    tableCounter++;
                    setOfFurniture.Table = expensiveTable;
                }
                else if (expensiveTable == null)
                {
                    Console.WriteLine($"We don't have {sizeOfTable} {materialOfTable} Tables in stock, " +
                                      $"please choose another size and/or material.");
                }
            }
        }
コード例 #3
0
ファイル: ChairServices.cs プロジェクト: 7denth/Final-Project
 public string GetChairMaterialType(Kit setOfFurniture)
 {
     if (setOfFurniture.Table.Material.ToLower().Equals("wood"))
     {
         return("wood");
     }
     else if (setOfFurniture.Table.Material.ToLower().Equals("plastic"))
     {
         return("plastic");
     }
     else
     {
         Console.WriteLine("For glass table please choose either wood or plastic chairs.");
         return(FurnitureServices.GetSizeOrMaterial(FurnitureServices.chairMaterialTypes));
     }
 }
コード例 #4
0
        public void FillInKit(Kit setOfFurniture, List <Table> tables, List <Chair> chairs)
        {
            TableServices tableServices      = new TableServices();
            ChairServices chairServices      = new ChairServices();
            int           generalCounter     = 0;
            int           smallWoodTable     = tableServices.CountTablesOfEachType("wood", "small", tables);
            int           smallPlasticTable  = tableServices.CountTablesOfEachType("plastic", "small", tables);
            int           smallGlassTable    = tableServices.CountTablesOfEachType("glass", "small", tables);
            int           woodPricedChair    = chairServices.GetChairsOfOneTypeAtOnePrice("wood", chairs, setOfChairs).Count();
            int           plasticPricedChair = chairServices.GetChairsOfOneTypeAtOnePrice("plastic", chairs, setOfChairs).Count();

            Console.WriteLine("Lets build a set of furniture from what we have in stock.");
            setOfFurniture.Name = FurnitureServices.GetNameOfSet();

            if (tables.Count() == 0)
            {
                Console.WriteLine("There is no tables in stock. Unfortunatelly we can not produce any set of furniture.");
            }
            else
            {
                while (generalCounter == 0)
                {
                    tableServices.FindTable(setOfFurniture, tables);
                    setOfChairs   = chairServices.GetNumberOfChairs(setOfFurniture);
                    chairMaterial = chairServices.GetChairMaterialType(setOfFurniture);
                    IEnumerable <Chair> chairsOfOneTypeAtOnePrice = chairServices.GetChairsOfOneTypeAtOnePrice(chairMaterial, chairs, setOfChairs);

                    if (chairsOfOneTypeAtOnePrice.Count() >= setOfChairs)
                    {
                        foreach (Chair y in chairsOfOneTypeAtOnePrice)
                        {
                            generalCounter++;
                            setOfFurniture.GetList().Add(y);
                            if (setOfFurniture.GetList().Count == setOfChairs)
                            {
                                int newCounter = 0;
                                foreach (var c in setOfFurniture.GetList())
                                {
                                    chairs.Remove(c);
                                }
                                foreach (Chair x in chairs)
                                {
                                    newCounter++;
                                }
                                tables.Remove(setOfFurniture.Table);
                                break;
                            }
                        }
                        Console.WriteLine($"\n{ShowResult(setOfFurniture)}");
                    }
                    else if ((chairsOfOneTypeAtOnePrice.Count() <= setOfChairs &&
                              (chairServices.GetChairsOfOneTypeAtOnePrice("wood", chairs, setOfChairs).Count() >= 2)) && (smallWoodTable > 0 || smallGlassTable > 0))
                    {
                        Console.WriteLine("Try other combinations.");
                    }
                    else if ((chairsOfOneTypeAtOnePrice.Count() <= setOfChairs &&
                              (chairServices.GetChairsOfOneTypeAtOnePrice("plastic", chairs, setOfChairs).Count() >= 2)) && (smallPlasticTable > 0 || smallGlassTable > 0))
                    {
                        Console.WriteLine("Try other combinations.");
                    }
                    else if (woodPricedChair < 2 || (woodPricedChair < 2 && (smallWoodTable < 1 || smallGlassTable < 1)) ||
                             plasticPricedChair < 2 || (plasticPricedChair < 2 && (smallPlasticTable < 1 || smallGlassTable < 1)))
                    {
                        generalCounter--;
                        Console.WriteLine("There is not enough chairs to make any set.");
                    }
                }
            }
        }