static void Main(string[] args) { Console.Write("Enter the number of slots:"); int slots = int.Parse(Console.ReadLine()); List <ProductCar> cars = AddCars(slots); Invoker invoker = new Invoker(); while (true) { Console.WriteLine("Enter command:"); string command = Console.ReadLine(); switch (command) { case "count types": CountTypesReceiver countTypesReceiver = new CountTypesReceiver(); invoker.SetCommand(new CountTypesCommand(countTypesReceiver, cars)); invoker.Run(); break; case "count all": CountAllReceiver countAllReceiver = new CountAllReceiver(); invoker.SetCommand(new CountAllCommand(countAllReceiver, cars)); invoker.Run(); break; case "average price": AveragePriceReceiver averagePriceReceiver = new AveragePriceReceiver(); invoker.SetCommand(new AveragePriceCommand(averagePriceReceiver, cars)); invoker.Run(); break; case "exit": ExitReceiver exitReceiver = new ExitReceiver(); invoker.SetCommand(new ExitCommand(exitReceiver)); invoker.Run(); break; } foreach (ProductCar car in cars) { string helper = "average price " + car.Type; if (command == helper) { AveragePriceTypeReceiver averagePriceTypeReceiver = new AveragePriceTypeReceiver(); invoker.SetCommand(new AveragePriceTypeCommand(averagePriceTypeReceiver, cars, car.Type)); invoker.Run(); } break; } } }
public AveragePriceCommand(AveragePriceReceiver receiver, List <ProductCar> cars) { this.receiver = receiver; this.cars = cars; }