Beispiel #1
0
        private static void FindProductsByName(string[] elements, ShoppingCenter shoppingCenter)
        {
            var name     = elements[0];
            var products = shoppingCenter.FindProductsByName(name);

            PrintProducts(products);
        }
Beispiel #2
0
        private static void CallCommand(ShoppingCenter shoppingCenter, string command, string[] elements)
        {
            switch (command)
            {
            case "AddProduct":
                AddProduct(elements, shoppingCenter);
                break;

            case "DeleteProducts":
                DeleteProducts(elements, shoppingCenter);
                break;

            case "FindProductsByName":
                FindProductsByName(elements, shoppingCenter);
                break;

            case "FindProductsByProducer":
                FindProductsByProducer(elements, shoppingCenter);
                break;

            case "FindProductsByPriceRange":
                FindProductsByPriceRange(elements, shoppingCenter);
                break;
            }
        }
Beispiel #3
0
        private static void FindProductsByProducer(string[] elements, ShoppingCenter shoppingCenter)
        {
            var producer = elements[0];
            var products = shoppingCenter.FindProductsByProducer(producer);

            PrintProducts(products);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var shoppingCenter = new ShoppingCenter();

            for (int i = 0; i < n; i++)
            {
                var line   = Console.ReadLine();
                var tokens = line.Split(new[] { " " }, StringSplitOptions.None);

                switch (tokens[0])
                {
                case "AddProduct":
                    AddProduct(shoppingCenter, line, tokens);
                    break;

                case "DeleteProducts":
                    DeleteProducts(shoppingCenter, line, tokens);
                    break;

                case "FindProductsByProducer":
                    FindProductsByProducer(shoppingCenter, line);
                    break;

                case "FindProductsByName":
                    FindProductsByName(shoppingCenter, line);
                    break;

                case "FindProductsByPriceRange":
                    FindProductsByPriceRange(shoppingCenter, line);
                    break;
                }
            }
        }
Beispiel #5
0
        private static void FindProductsByName(ShoppingCenter shoppingCenter, string line)
        {
            var name     = line.Substring(line.IndexOf(" ") + 1);
            var products = shoppingCenter.FindProductsByName(name);

            PrintProducts(products);
        }
    public static void Main()
    {
        var shoppingCenter = new ShoppingCenter();

        var linesCount = int.Parse(Console.ReadLine());

        for (int i = 0; i < linesCount; i++)
        {
            var line   = Console.ReadLine(); // {command} {arg1};{arg2};{...}
            var tokens = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (tokens.Length < 2) // {command} {args}
            {
                continue;
            }

            var command = tokens[0];
            var args    = GetCommandArgs(line);

            switch (command)
            {
            case "AddProduct": AddProduct(shoppingCenter, args); break;

            case "DeleteProducts": DeleteProducts(shoppingCenter, args); break;

            case "FindProductsByName": FindProductsByName(shoppingCenter, args); break;

            case "FindProductsByProducer": FindProductsByProducer(shoppingCenter, args); break;

            case "FindProductsByPriceRange": FindProductsByPriceRange(shoppingCenter, args); break;

            default: break;
            }
        }
    }
Beispiel #7
0
        private static void FindProductsByProducer(ShoppingCenter shoppingCenter, string line)
        {
            var productTokens = SplitLine(line);
            var producer      = productTokens[0].Substring(productTokens[0].IndexOf(" ") + 1);
            var products      = shoppingCenter.FindProductsByProducer(producer);

            PrintProducts(products);
        }
Beispiel #8
0
        private static void FindProductsByPriceRange(string[] elements, ShoppingCenter shoppingCenter)
        {
            var fromPrice = decimal.Parse(elements[0]);
            var toPrice   = decimal.Parse(elements[1]);
            var products  = shoppingCenter.FindProductsByPriceRange(fromPrice, toPrice);

            PrintProducts(products);
        }
Beispiel #9
0
        private static void AddProduct(ShoppingCenter shoppingCenter, string line, string[] tokens)
        {
            var productTokens = SplitLine(line);
            var name          = productTokens[0].Substring(productTokens[0].IndexOf(" ") + 1);

            shoppingCenter.AddProduct(name, decimal.Parse(productTokens[1]), productTokens[2]);
            Console.WriteLine("Product added");
        }
Beispiel #10
0
        private static void FindProductsByPriceRange(ShoppingCenter shoppingCenter, string line)
        {
            var productTokens = SplitLine(line);
            var fromPrice     = productTokens[0].Substring(productTokens[0].IndexOf(" ") + 1);
            var products      = shoppingCenter.FindProductsByPriceRange(decimal.Parse(fromPrice), decimal.Parse(productTokens[1]));

            PrintProducts(products);
        }
Beispiel #11
0
    private static void FindProductsByName(ShoppingCenter shoppingCenter, string[] args)
    {
        if (!args.Any())
        {
            return;
        }

        var result = shoppingCenter.FindProductsByName(args[0]);

        Print(result);
    }
Beispiel #12
0
    public static void Main()
    {
        IShoppingCenter shoppingCenter = new ShoppingCenter();
        //IShoppingCenter shoppingCenter = new ShoppingCenterSlow();

        IReader reader = new ConsoleReader();
        IWriter writer = new ConsoleWriter();

        IEngine engine = new Engine(shoppingCenter, reader, writer);

        engine.Run();
    }
Beispiel #13
0
        static void Main(string[] args)
        {
            var shoppingCenter = new ShoppingCenter();
            var n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                var line     = Console.ReadLine();
                var command  = line.Substring(0, line.IndexOf(" "));
                var elements = line.Substring(line.IndexOf(" ") + 1).Split(new[] { ";" }, StringSplitOptions.None);
                CallCommand(shoppingCenter, command, elements);
            }
        }
Beispiel #14
0
    private static void FindProductsByPriceRange(ShoppingCenter shoppingCenter, string[] args)
    {
        if (args.Length < 2)
        {
            return;
        }

        var startPrice = decimal.Parse(args[0]);
        var endPrice   = decimal.Parse(args[1]);
        var products   = shoppingCenter.FindProductsByPriceRange(startPrice, endPrice);

        Print(products);
    }
Beispiel #15
0
    static void Main()
    {
        ShoppingCenter engine           = new ShoppingCenter();
        int            numberOfCommands = int.Parse(Console.ReadLine());

        StringBuilder result = new StringBuilder();

        for (int i = 0; i < numberOfCommands; i++)
        {
            result.AppendLine(engine.ParseCommands(Console.ReadLine()));
        }

        Console.WriteLine(result.ToString());
    }
Beispiel #16
0
        private static void DeleteProducts(ShoppingCenter shoppingCenter, string line, string[] tokens)
        {
            var productTokens = SplitLine(line);
            var name          = productTokens[0].Substring(productTokens[0].IndexOf(" ") + 1);

            if (productTokens.Length == 1)
            {
                Console.WriteLine(shoppingCenter.DeleteProducts(name));
            }
            else
            {
                Console.WriteLine(shoppingCenter.DeleteProducts(name, productTokens[1]));
            }
        }
Beispiel #17
0
    static void Main()
    {
        ShoppingCenter engine = new ShoppingCenter();
        int numberOfCommands = int.Parse(Console.ReadLine());

        StringBuilder result = new StringBuilder();

        for (int i = 0; i < numberOfCommands; i++)
        {
            result.AppendLine(engine.ParseCommands(Console.ReadLine()));
        }

        Console.WriteLine(result.ToString());
    }
Beispiel #18
0
    private static void AddProduct(ShoppingCenter shoppingCenter, string[] args)
    {
        if (args.Length < 3)
        {
            return;
        }

        var name     = args[0];
        var price    = decimal.Parse(args[1]);
        var producer = args[2];
        var product  = new Product(name, price, producer);

        shoppingCenter.AddProduct(product);
        Console.WriteLine("Product added");
    }
    static void Main(string[] args)
    {
        var lines = int.Parse(Console.ReadLine());

        var center = new ShoppingCenter();

        for (int i = 0; i < lines; i++)
        {
            var input = Console.ReadLine();
            var index = input.IndexOf(' ');

            var command = input.Substring(0, index);
            var cmdArgs = input.Substring(index + 1).Split(';');

            switch (command)
            {
            case "AddProduct":
                Console.WriteLine(center.AddProduct(cmdArgs[0], decimal.Parse(cmdArgs[1]), cmdArgs[2]));
                break;

            case "DeleteProducts":
                Console.WriteLine(
                    cmdArgs.Length == 1
                            ? center.DeleteProducts(cmdArgs[0])
                            : center.DeleteProducts(cmdArgs[0], cmdArgs[1]));
                break;

            case "FindProductsByName":
                Console.Write(center.FindProductsByName(cmdArgs[0]));
                break;

            case "FindProductsByProducer":
                Console.Write(center.FindProductsByProducer(cmdArgs[0]));
                break;

            case "FindProductsByPriceRange":
                Console.Write(center.FindProductsByPriceRange(decimal.Parse(cmdArgs[0]), decimal.Parse(cmdArgs[1])));
                break;

            default:
                throw new ArgumentException();
            }
        }
    }
    public static void Main()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

        ShoppingCenter center = new ShoppingCenter();

        StringBuilder answer = new StringBuilder();

        int commands = int.Parse(Console.ReadLine());

        for (int i = 1; i <= commands; i++)
        {
            string command       = Console.ReadLine();
            string commandResult = center.ProcessCommand(command);
            answer.AppendLine(commandResult);
        }

        Console.Write(answer);
    }
Beispiel #21
0
        private static void DeleteProducts(string[] elements, ShoppingCenter shoppingCenter)
        {
            var count = 0;

            if (elements.Length == 2)
            {
                count = shoppingCenter.DeleteProducts(elements[0], elements[1]);
            }
            else
            {
                count = shoppingCenter.DeleteProducts(elements[0]);
            }

            if (count == 0)
            {
                Console.WriteLine("No products found");
            }
            else
            {
                Console.WriteLine($"{count} products deleted");
            }
        }
Beispiel #22
0
    private static void DeleteProducts(ShoppingCenter shoppingCenter, string[] args)
    {
        if (!args.Any())
        {
            return;
        }

        var count = 0;

        if (args.Length > 1)
        {
            var name     = args[0];
            var producer = args[1];
            count = shoppingCenter.DeleteProductsByNameAndProducer(name, producer);
        }
        else
        {
            count = shoppingCenter.DeleteProductsByProducer(args[0]);
        }

        Print(count);
    }
Beispiel #23
0
    public static void Main()
    {
        ShoppingCenter center = new ShoppingCenter();

        int commandsCount = int.Parse(Console.ReadLine());

        for (int i = 0; i < commandsCount; i++)
        {
            string line    = Console.ReadLine();
            string command = line.Split(' ').ToArray()[0];
            line = line.Substring(line.IndexOf(' ') + 1);

            switch (command)
            {
            case "AddProduct":
                string[] tokens = line.Split(';').ToArray();
                Product  p      = new Product(tokens[0], double.Parse(tokens[1]), tokens[2]);
                center.AddProduct(p);
                Console.WriteLine("Product added");
                break;

            case "FindProductsByName":
                List <Product> foundByName = center.FindProductsByName(line).ToList();
                if (foundByName.Count == 0)
                {
                    Console.WriteLine("No products found");
                }
                else
                {
                    Console.WriteLine(string.Join("\n", foundByName));
                }

                break;

            case "FindProductsByProducer":

                List <Product> foundByProducer = center.FindProductsByProducer(line).ToList();
                if (foundByProducer.Count == 0)
                {
                    Console.WriteLine("No products found");
                }
                else
                {
                    Console.WriteLine(string.Join("\n", foundByProducer));
                }
                break;

            case "FindProductsByPriceRange":

                string[]       prices = line.Split(';').ToArray();
                double         price1 = double.Parse(prices[0]);
                double         price2 = double.Parse(prices[1]);
                List <Product> found  = center.FindProductsByPriceRange(price1, price2).ToList();
                if (found.Count == 0)
                {
                    Console.WriteLine("No products found");
                }
                else
                {
                    Console.WriteLine(string.Join("\n", found));
                }

                break;

            case "DeleteProducts":

                if (line.Contains(';'))
                {
                    string[] args            = line.Split(';').ToArray();
                    int      deletedProducts = center.DeleteProducts(args[0], args[1]);
                    if (deletedProducts == 0)
                    {
                        Console.WriteLine("No products found");
                    }
                    else
                    {
                        Console.WriteLine($"{deletedProducts} products deleted");
                    }
                }
                else
                {
                    int deletedProducts = center.DeleteProducts(line);
                    if (deletedProducts == 0)
                    {
                        Console.WriteLine("No products found");
                    }
                    else
                    {
                        Console.WriteLine($"{deletedProducts} products deleted");
                    }
                }

                break;
            }
        }
    }
    static void Main(string[] args)
    {
        int numberOfCommands = int.Parse(Console.ReadLine());

        ShoppingCenter shoppingCenter = new ShoppingCenter();

        output = new StringBuilder();

        for (int i = 0; i < numberOfCommands; i++)
        {
            string commandLine = Console.ReadLine();

            int    indexFirstInterval      = commandLine.IndexOf(' ');
            string command                 = commandLine.Substring(0, indexFirstInterval);
            string commandParametersString = commandLine.Substring(indexFirstInterval + 1);

            string[] commandParameters = commandParametersString.Split(new char[] { ';' });

            switch (command)
            {
            case "AddProduct":
                shoppingCenter.Add(commandParameters[0], decimal.Parse(commandParameters[1]), commandParameters[2]);
                output.AppendLine("Product added");
                break;

            case "FindProductsByName":
                Product[] findByNameResult = shoppingCenter.FindProductByName(commandParameters[0]);
                Array.Sort(findByNameResult);
                PrintProductArray(findByNameResult);
                break;

            case "FindProductsByPriceRange":
                Product[] findByPriceResult =
                    shoppingCenter.FindProductByPriceRange(decimal.Parse(commandParameters[0]), decimal.Parse(commandParameters[1]));
                Array.Sort(findByPriceResult);
                PrintProductArray(findByPriceResult);
                break;

            case "FindProductsByProducer":
                Product[] findByProducerResult = shoppingCenter.FindProductByProducer(commandParameters[0]);
                Array.Sort(findByProducerResult);
                PrintProductArray(findByProducerResult);
                break;

            case "DeleteProducts":
                int deletedProducts;
                if (commandParameters.Length == 2)
                {
                    deletedProducts = shoppingCenter.DeleteProduct(commandParameters[0], commandParameters[1]);
                }
                else
                {
                    deletedProducts = shoppingCenter.DeleteProduct(commandParameters[0]);
                }

                if (deletedProducts == 0)
                {
                    output.AppendLine("No products found");
                }
                else
                {
                    output.AppendLine(deletedProducts + " products deleted");
                }
                break;

            default:
                break;
            }
        }

        Console.WriteLine(output.ToString().Trim());
    }
Beispiel #25
0
    static void Main()
    {
        int            commandsNumber = int.Parse(Console.ReadLine());
        ShoppingCenter shoppingCenter = new ShoppingCenter();

        for (int i = 0; i < commandsNumber; i++)
        {
            string line       = Console.ReadLine();
            int    firstSpace = line.IndexOf(" ");

            string   command = line.Substring(0, firstSpace);
            string[] tokens  = line.Substring(firstSpace + 1).Split(';');

            switch (command)
            {
            case "AddProduct":
                string name     = tokens[0];
                double price    = double.Parse(tokens[1]);
                string producer = tokens[2];

                Product p = new Product(name, price, producer);

                shoppingCenter.Add(p);
                Console.WriteLine("Product added");
                break;

            case "DeleteProducts":
                if (tokens.Length == 1)
                {
                    producer = tokens[0];
                    int countDeleted = shoppingCenter.DeleteProductsByProducer(producer);

                    if (countDeleted == 0)
                    {
                        Console.WriteLine("No products found");
                    }
                    else
                    {
                        Console.WriteLine(countDeleted.ToString() + " products deleted");
                    }
                }
                else
                {
                    name     = tokens[0];
                    producer = tokens[1];
                    int countDeleted = shoppingCenter.DeleteProductsByProducerAndName(name, producer);

                    if (countDeleted == 0)
                    {
                        Console.WriteLine("No products found");
                    }
                    else
                    {
                        Console.WriteLine(countDeleted.ToString() + " products deleted");
                    }
                }

                break;

            case "FindProductsByName":
                name = tokens[0];
                List <Product> result = shoppingCenter.FindProductsByName(name).ToList();
                if (result.Count != 0)
                {
                    Console.WriteLine(string.Join(Environment.NewLine, result));
                }
                else
                {
                    Console.WriteLine("No products found");
                }

                break;

            case "FindProductsByProducer":
                producer = tokens[0];
                result   = shoppingCenter.FindProductsByProducer(producer).ToList();
                if (result.Count != 0)
                {
                    Console.WriteLine(string.Join(Environment.NewLine, result));
                }
                else
                {
                    Console.WriteLine("No products found");
                }

                break;

            case "FindProductsByPriceRange":
                double priceLow  = double.Parse(tokens[0]);
                double priceHigh = double.Parse(tokens[1]);
                result = shoppingCenter.FindProductsByPriceRange(priceLow, priceHigh)
                         .ToList();

                if (result.Count != 0)
                {
                    Console.WriteLine(string.Join(Environment.NewLine, result));
                }
                else
                {
                    Console.WriteLine("No products found");
                }

                break;
            }
        }
    }
Beispiel #26
0
    public static void Main()
    {
        ShoppingCenter shoppingCenter   = new ShoppingCenter();
        int            numberOfCommands = int.Parse(Console.ReadLine());

        for (int i = 0; i < numberOfCommands; i++)
        {
            string commandLine = Console.ReadLine();

            string   command = commandLine.Remove(commandLine.IndexOf(' '));
            string[] items   = commandLine
                               .Substring(command.Length + 1)
                               .Split(';');

            switch (command)
            {
            case "AddProduct":
                Product product = new Product(items[0], double.Parse(items[1], CultureInfo.InvariantCulture), items[2]);
                shoppingCenter.AddProduct(product);
                Console.WriteLine("Product added");
                break;

            case "DeleteProducts":
                int count = 0;

                if (items.Length == 2)
                {
                    count = shoppingCenter.DeleteProducts(items[0], items[1]);
                }
                else if (items.Length == 1)
                {
                    count = shoppingCenter.DeleteProducts(items[0]);
                }

                string resultToPrint = count > 0 ?
                                       $"{count} products deleted" : "No products found";
                Console.WriteLine(resultToPrint);

                break;

            case "FindProductsByName":
                IEnumerable <Product> findProducts = shoppingCenter
                                                     .FindProductsByName(items[0])
                                                     .ToList();

                if (findProducts.Count() == 0)
                {
                    Console.WriteLine("No products found");
                }
                else
                {
                    Console.WriteLine(string.Join("\n", findProducts));
                }

                break;

            case "FindProductsByProducer":
                IEnumerable <Product> findProductsByProducer = shoppingCenter
                                                               .FindProductsByProducer(items[0])
                                                               .ToList();

                if (findProductsByProducer.Count() == 0)
                {
                    Console.WriteLine("No products found");
                }
                else
                {
                    Console.WriteLine(string.Join("\n", findProductsByProducer));
                }

                break;

            case "FindProductsByPriceRange":
                IEnumerable <Product> findInRange =
                    shoppingCenter.FindProductsByPriceRange(
                        double.Parse(items[0], CultureInfo.InvariantCulture),
                        double.Parse(items[1], CultureInfo.InvariantCulture))
                    .ToList();

                if (findInRange.Count() == 0)
                {
                    Console.WriteLine("No products found");
                }
                else
                {
                    Console.WriteLine(string.Join("\n", findInRange));
                }

                break;
            }
        }
    }
Beispiel #27
0
 private static void AddProduct(string[] elements, ShoppingCenter shoppingCenter)
 {
     shoppingCenter.AddProduct(elements[0], decimal.Parse(elements[1]), elements[2]);
     Console.WriteLine("Product added");
 }
Beispiel #28
0
    static void Main()
    {
        int            commandsNumber = int.Parse(Console.ReadLine());
        ShoppingCenter center         = new ShoppingCenter();

        for (int i = 0; i < commandsNumber; i++)
        {
            string line       = Console.ReadLine();
            int    firstSpace = line.IndexOf(" ");

            string   command = line.Substring(0, firstSpace);
            string[] tokens  = line.Substring(firstSpace + 1).Split(';');


            switch (command)
            {
            case "AddProduct":
            {
                string name     = tokens[0];
                double price    = double.Parse(tokens[1]);
                string producer = tokens[2];

                Product p = new Product(name, price, producer);
                center.Add(p);
                Console.WriteLine("Product added");
                break;
            }

            case "DeleteProducts":
                if (tokens.Length == 1)
                {
                    int count = center.DeleteProductsByProducer(tokens[0]);

                    if (count == 0)
                    {
                        Console.WriteLine("No products found");
                    }
                    else
                    {
                        Console.WriteLine(count.ToString() + " products deleted");
                    }
                }
                else
                {
                    int count = center.DeleteProductsByProducerAndName(
                        tokens[0],
                        tokens[1]);
                    if (count == 0)
                    {
                        Console.WriteLine("No products found");
                    }
                    else
                    {
                        Console.WriteLine(count.ToString() + " products deleted");
                    }
                }
                break;

            case "FindProductsByName":

                List <Product> result =
                    center.FindProductsByName(tokens[0]).ToList();
                if (result.Count != 0)
                {
                    Console.WriteLine(string.Join("\n", result));
                }
                else
                {
                    Console.WriteLine("No products found");
                }
                break;

            case "FindProductsByProducer":
                List <Product> result2 =
                    center.FindProductsByProducer(tokens[0]).ToList();

                if (result2.Count != 0)
                {
                    Console.WriteLine(string.Join("\n", result2));
                }
                else
                {
                    Console.WriteLine("No products found");
                }

                break;

            case "FindProductsByPriceRange":
                IEnumerable <Product> result3 =
                    center.FindProductsByPriceRange(
                        double.Parse(tokens[0]),
                        double.Parse(tokens[1]))
                    .OrderBy(x => x);

                if (result3.Any())
                {
                    Console.WriteLine(string.Join("\n", result3));
                }
                else
                {
                    Console.WriteLine("No products found");
                }
                break;
            }
        }
    }
Beispiel #29
0
    public static void Main()
    {
        var sc = new ShoppingCenter();

        var commands = int.Parse(Console.ReadLine());

        for (int i = 0; i < commands; i++)
        {
            string line = Console.ReadLine();

            int firstSpace = line.IndexOf(" ");

            string   command = line.Substring(0, firstSpace);
            string[] tokens  = line.Substring(firstSpace + 1).Split(';');

            switch (command)
            {
            case "AddProduct":
            {
                string addName     = tokens[0];
                double addPrice    = double.Parse(tokens[1]);
                string addProducer = tokens[2];
                sc.AddProduct(addName, addPrice, addProducer);
                Console.WriteLine("Product added");
                break;
            }

            case "DeleteProducts":
            {
                int count = 0;
                if (tokens.Length == 1)
                {
                    string currProducer = tokens[0];
                    count = sc.DeleteProductsByProducer(currProducer);
                }
                else
                {
                    string deleteName     = tokens[0];
                    string deleteProducer = tokens[1];
                    count = sc.DeleteProductsByProducerAndName(deleteName, deleteProducer);
                }
                PrintRemoveMessage(count);
                break;
            }

            case "FindProductsByName":
            {
                string findByName = tokens[0];
                PrintProducts(sc.FindProductsByName(findByName).ToList());
                break;
            }

            case "FindProductsByProducer":
            {
                string findByProd = tokens[0];
                PrintProducts(sc.FindProductsByProducer(findByProd).ToList());
                break;
            }

            case "FindProductsByPriceRange":
            {
                double lowerRange = double.Parse(tokens[0]);
                double upperRange = double.Parse(tokens[1]);

                PrintProducts(sc.FindProductsByPriceRange(lowerRange, upperRange).OrderBy(x => x).ToList());
                break;
            }
            }
        }
    }
Beispiel #30
0
    public static void Main()
    {
        int            commandsNumber = int.Parse(Console.ReadLine());
        ShoppingCenter center         = new ShoppingCenter();

        for (int i = 0; i < commandsNumber; i++)
        {
            string line = Console.ReadLine();

            int firstSpace = line.IndexOf(" ");

            string         command = line.Substring(0, firstSpace);
            string[]       args    = line.Substring(firstSpace + 1).Split(';');
            List <Product> result  = new List <Product>();
            switch (command)
            {
            case "AddProduct":
                string name     = args[0];
                double price    = double.Parse(args[1]);
                string producer = args[2];

                Product p = new Product(name, price, producer);
                center.Add(p);
                Console.WriteLine("Product added");
                break;

            case "DeleteProducts":
                int count = 0;
                if (args.Length == 1)      // delete producer
                {
                    count = center.DeleteProductsByProducer(args[0]);
                }
                else
                {
                    count = center.DeleteProductsByProducerAndName(
                        args[0],
                        args[1]);
                }
                if (count == 0)
                {
                    Console.WriteLine("No products found");
                }
                else
                {
                    Console.WriteLine(count + " products deleted");
                }
                break;

            case "FindProductsByName":
                result = center.FindProductsByName(args[0]).ToList();
                break;

            case "FindProductsByProducer":
                result = center.FindProductsByProducer(args[0]).ToList();
                break;

            case "FindProductsByPriceRange":
                result = center.FindProductsByPriceRange(
                    double.Parse(args[0]),
                    double.Parse(args[1]))
                         .OrderBy(x => x)
                         .ToList();
                break;
            }
            if (command.StartsWith("Find"))
            {
                if (result.Count != 0)
                {
                    Console.WriteLine(string.Join("\n", result));
                }
                else
                {
                    Console.WriteLine("No products found");
                }
            }
        }
    }
Beispiel #31
0
    public static void Main()
    {
#if DEBUG
        Console.SetIn(new StreamReader("../../input.txt"));
        Debug.Listeners.Add(new ConsoleTraceListener());
#endif

        var date = DateTime.Now;

        var separator = new[] { ' ' };

        var shoppingCenter = new ShoppingCenter();

        foreach (int i in Enumerable.Range(0, int.Parse(Console.ReadLine())))
        {
            var line = Console.ReadLine();
            var splitted = line.Split(separator, 2);
            var name = splitted[0];
            var parameters = splitted[1].Split(';');

#if DEBUG
            Output.AppendLine();
            Output.AppendLine(line);
#endif

            switch (name)
            {
                case "AddProduct":
                    {
                        var product = new Product(
                            name: parameters[0],
                            price: decimal.Parse(parameters[1]),
                            producer: parameters[2]
                        );

                        shoppingCenter.AddProduct(product);

                        Output.AppendLine("Product added");
                        break;
                    }

                case "FindProductsByName":
                    {
                        var products = shoppingCenter.FindProductsByName(parameters[0]);

                        PrintProducts(products);

                        break;
                    }

                case "FindProductsByProducer":
                    {
                        var products = shoppingCenter.FindProductsByProducer(parameters[0]);

                        PrintProducts(products);

                        break;
                    }

                case "FindProductsByPriceRange":
                    {
                        var products = shoppingCenter.FindProductsByPriceRange(
                            min: decimal.Parse(parameters[0]),
                            max: decimal.Parse(parameters[1])
                        );

                        PrintProducts(products);

                        break;
                    }

                case "DeleteProducts":
                    {
                        int deletedCount;

                        switch (parameters.Length)
                        {
                            case 1:
                                deletedCount = shoppingCenter.DeleteProducts(
                                    producer: parameters[0]
                                );

                                break;

                            case 2:
                                deletedCount = shoppingCenter.DeleteProducts(
                                    name: parameters[0],
                                    producer: parameters[1]
                                );

                                break;

                            default:
                                throw new ArgumentException("DeleteProducts");
                        }

                        if (deletedCount == 0)
                        {
                            Output.AppendLine("No products found");
                            break;
                        }

                        Output.AppendLine(deletedCount + " products deleted");

                        break;
                    }

                default:
                    throw new ArgumentException("Invalid command: " + name);
            }
        }

#if !DEBUG || DEBUG
        Console.Write(Output);
#endif

        Debug.WriteLine(DateTime.Now - date);
    }
Beispiel #32
0
    public static void Main()
    {
#if DEBUG
        Console.SetIn(new StreamReader("../../input.txt"));
        Debug.Listeners.Add(new ConsoleTraceListener());
#endif

        var date = DateTime.Now;

        var separator = new[] { ' ' };

        var shoppingCenter = new ShoppingCenter();

        foreach (int i in Enumerable.Range(0, int.Parse(Console.ReadLine())))
        {
            var line       = Console.ReadLine();
            var splitted   = line.Split(separator, 2);
            var name       = splitted[0];
            var parameters = splitted[1].Split(';');

#if DEBUG
            Output.AppendLine();
            Output.AppendLine(line);
#endif

            switch (name)
            {
            case "AddProduct":
            {
                var product = new Product(
                    name: parameters[0],
                    price: decimal.Parse(parameters[1]),
                    producer: parameters[2]
                    );

                shoppingCenter.AddProduct(product);

                Output.AppendLine("Product added");
                break;
            }

            case "FindProductsByName":
            {
                var products = shoppingCenter.FindProductsByName(parameters[0]);

                PrintProducts(products);

                break;
            }

            case "FindProductsByProducer":
            {
                var products = shoppingCenter.FindProductsByProducer(parameters[0]);

                PrintProducts(products);

                break;
            }

            case "FindProductsByPriceRange":
            {
                var products = shoppingCenter.FindProductsByPriceRange(
                    min: decimal.Parse(parameters[0]),
                    max: decimal.Parse(parameters[1])
                    );

                PrintProducts(products);

                break;
            }

            case "DeleteProducts":
            {
                int deletedCount;

                switch (parameters.Length)
                {
                case 1:
                    deletedCount = shoppingCenter.DeleteProducts(
                        producer: parameters[0]
                        );

                    break;

                case 2:
                    deletedCount = shoppingCenter.DeleteProducts(
                        name: parameters[0],
                        producer: parameters[1]
                        );

                    break;

                default:
                    throw new ArgumentException("DeleteProducts");
                }

                if (deletedCount == 0)
                {
                    Output.AppendLine("No products found");
                    break;
                }

                Output.AppendLine(deletedCount + " products deleted");

                break;
            }

            default:
                throw new ArgumentException("Invalid command: " + name);
            }
        }

#if !DEBUG || DEBUG
        Console.Write(Output);
#endif

        Debug.WriteLine(DateTime.Now - date);
    }