예제 #1
0
파일: Program.cs 프로젝트: mfratassi/course
        static void ProgramaSete()
        {
            List <Product> products = new List <Product>();
            Product        product;

            Console.WriteLine();

            Console.WriteLine("Number of products: ");
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine($"Product #{i + 1} data: ");
                Console.Write("Common, used or imported (c/u/i)? ");
                char type = char.Parse(Console.ReadLine());
                Console.Write("Name: ");
                string name = Console.ReadLine();
                Console.Write("Price: ");
                double price = double.Parse(Console.ReadLine());

                if (type == 'i' || type == 'I')
                {
                    Console.Write("Enter customs fee: ");
                    double customsFee = double.Parse(Console.ReadLine());
                    product = new ImportedProduct(name, price, customsFee);
                }
                else if (type == 'u' || type == 'U')
                {
                    Console.Write("Enter manufature date: ");
                    DateTime manufactureDate = DateTime.Parse(Console.ReadLine());
                    product = new UsedProduct(name, price, manufactureDate);
                }
                else
                {
                    product = new Product(name, price);
                }

                products.Add(product);
                Console.WriteLine("Success");
                Console.WriteLine();
            }

            Console.WriteLine("PRICE TAGS");
            foreach (Product p in products)
            {
                Console.WriteLine(p.PriceTag());
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.Write("Enter the number of products: ");
            int            n    = int.Parse(Console.ReadLine());
            List <Product> list = new List <Product>();

            for (int i = 1; i <= n; i++)
            {
                Console.WriteLine($"Product #{i} data:");
                Console.Write("Common, used or imported (c/u/i)? ");
                char ch = char.Parse(Console.ReadLine());
                Console.Write("Name: ");
                string productName = Console.ReadLine();
                Console.Write("Price: ");
                double productPrice = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
                if (ch == 'i' || ch == 'I')
                {
                    Console.Write("Customs fee: ");
                    double          customsFee = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
                    ImportedProduct ip         = new ImportedProduct(productName, productPrice, customsFee);
                    list.Add(ip);
                }
                else if (ch == 'u' || ch == 'U')
                {
                    Console.Write("Manufacture date (DD/MM/YYYY): ");
                    DateTime    manufactureDate = DateTime.Parse(Console.ReadLine());
                    UsedProduct up = new UsedProduct(productName, productPrice, manufactureDate);
                    list.Add(up);
                }
                else
                {
                    Product p = new Product(productName, productPrice);
                    list.Add(p);
                }
            }

            Console.WriteLine();
            Console.WriteLine("PRICE TAGS:");
            foreach (Product p in list)
            {
                Console.WriteLine(p.PriceTag());
            }
        }