static bool ShopsHaveMicrowaveOven(List <Shop> shops, MicrowaveOven microwaveOven) { bool shopsContainMicrowaveOven = true; foreach (var shop in shops) { if (!shop.HasMicrowaveOven(microwaveOven)) { shopsContainMicrowaveOven = false; } } return(shopsContainMicrowaveOven); }
static MicrowaveOven GetCheapestAPlusMicrowaveOven(List <Shop> shops) { var cheapestMicrowaveOven = new MicrowaveOven(); foreach (var shop in shops) { var microwaveOven = shop.GetCheapestAPlusMicrowaveOven(); if (microwaveOven != null) { if (cheapestMicrowaveOven.Price == 0) { cheapestMicrowaveOven = microwaveOven; } else if (microwaveOven.Price < cheapestMicrowaveOven.Price) { cheapestMicrowaveOven = microwaveOven; } } } return(cheapestMicrowaveOven.Price == 0 ? null : cheapestMicrowaveOven); }
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 PrintMicrowaveOvenToConsole(MicrowaveOven microwaveOven) { Console.WriteLine(microwaveOven != null ? microwaveOven.ToString() : "No microwave oven found!"); }