Exemple #1
0
        static void Main(string[] args)
        {
            List <Product> list = new List <Product>();

            Console.Write("Enter the number of products: ");
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] vect  = Console.ReadLine().Split(',');
                double   price = double.Parse(vect[1], CultureInfo.InvariantCulture);
                list.Add(new Product(vect[0], price));
            }

            CalculationService calculationService = new CalculationService();

            Product p = calculationService.Max(list); // <Product> is optional

            Console.WriteLine("Most expensive:");
            Console.WriteLine(p);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            List <Product> list = new List <Product>();

            Console.Write("Enter N: ");
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] vect  = Console.ReadLine().Split(',');
                string   name  = vect[0];
                double   price = double.Parse(vect[1], CultureInfo.InvariantCulture);

                list.Add(new Product(name, price));
            }

            CalculationService calculationService = new CalculationService();
            Product            max = calculationService.Max(list);

            Console.WriteLine($"Max: {max}");
        }
Exemple #3
0
        static void Main(string[] args)
        {
            List <Person> list = new List <Person>();

            Console.Write("How many people? ");
            int n = int.Parse(Console.ReadLine());

            for (int i = 1; i <= n; i++)
            {
                Console.WriteLine($"Enter data for person #{i}:");
                Console.Write("Elderly (y/n)? ");
                string elderly = Console.ReadLine();
                Console.Write("Name: ");
                string name = Console.ReadLine();
                Console.Write("Amount: ");
                double amount = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
                if (elderly == "y")
                {
                    list.Add(new ElderlyPerson()
                    {
                        Name = name, Amount = amount
                    });
                }
                else
                {
                    list.Add(new OrdinaryPerson()
                    {
                        Name = name, Amount = amount
                    });
                }
            }

            CalculationService calculationService = new CalculationService();
            double             total = calculationService.TotalBonus(list);

            Console.WriteLine("Total bonus = " + total.ToString("F2", CultureInfo.InvariantCulture));
        }