static bool ShopsHaveElectricKettle(List <Shop> shops, ElectricKettle electricKettle) { bool shopsContainElectricKettle = true; foreach (var shop in shops) { if (!shop.HasElectricKettle(electricKettle)) { shopsContainElectricKettle = false; } } return(shopsContainElectricKettle); }
static ElectricKettle GetCheapestAPlusElectricKettle(List <Shop> shops) { var cheapestElectricKettle = new ElectricKettle(); foreach (var shop in shops) { var electricKettle = shop.GetCheapestAPlusElectricKettle(); if (electricKettle != null) { if (cheapestElectricKettle.Price == 0) { cheapestElectricKettle = electricKettle; } else if (electricKettle.Price < cheapestElectricKettle.Price) { cheapestElectricKettle = electricKettle; } } } return(cheapestElectricKettle.Price == 0 ? null : cheapestElectricKettle); }
static Shop GetShopFromFile(string path) { var shop = new Shop(); using (var reader = new StreamReader(path)) { shop.Name = reader.ReadLine(); shop.Address = reader.ReadLine(); shop.Phone = reader.ReadLine(); string line; while ((line = reader.ReadLine()) != null) { var data = line.Split(';'); if (IsFridge(data)) { var fridge = new Fridge() { Manufacturer = data[0], Model = data[1], EnergyClass = data[2], Color = data[3], Price = double.Parse(data[4]), Capacity = double.Parse(data[5]), InstallationType = data[6], HasFreezer = bool.Parse(data[7]), Height = double.Parse(data[8]), Width = double.Parse(data[9]), Depth = double.Parse(data[10]) }; shop.Fridges.Add(fridge); } if (IsMicrowaveOven(data)) { var microwaveOven = new MicrowaveOven() { Manufacturer = data[0], Model = data[1], EnergyClass = data[2], Color = data[3], Price = double.Parse(data[4]), Power = double.Parse(data[5]), ProgramCount = int.Parse(data[6]) }; shop.MicrowaveOvens.Add(microwaveOven); } if (IsElectricKettle(data)) { var electricKettle = new ElectricKettle() { Manufacturer = data[0], Model = data[1], EnergyClass = data[2], Color = data[3], Price = double.Parse(data[4]), Power = double.Parse(data[5]), Capacity = double.Parse(data[6]) }; shop.ElectricKettles.Add(electricKettle); } } } return(shop); }
static void PrintElectricKettleToConsole(ElectricKettle electricKettle) { Console.WriteLine(electricKettle != null ? electricKettle.ToString() : "No electric kettle found!"); }