Пример #1
0
        static void Main(string[] args)
        {
            Product product         = new Product("Noteebok", 1100.00);
            Product productUsed     = new UsedProduct(DateTime.Today, "Iphone", 1100.00);
            Product productImported = new ImportedProduct("Tablet", 1100.00, 20.00);

            Console.WriteLine(productImported.PriceTag());
            Console.WriteLine(product.PriceTag());
            Console.WriteLine(productUsed.PriceTag());
        }
Пример #2
0
        static void Main(string[] args)
        {
            Product p1 = new Product("Iphone XI", 5000);
            Product p2 = new ImportedProduct("Iphone XI", 4000, 20);
            Product p3 = new UsedProduct("Iphone 6", 800, new DateTime(2016, 06, 01));

            Console.WriteLine(p1.PriceTag());
            Console.WriteLine(p2.PriceTag());
            Console.WriteLine(p3.PriceTag());
        }
Пример #3
0
        static void Main(string[] args)
        {
            Product pro = new ImportedProduct("Monitor", 1000.00, 150.00);

            Product pro2 = new UsedProduct("Mouse", 100.00, DateTime.Parse("2019-10-10"));

            System.Console.WriteLine(pro.PriceTag());

            System.Console.WriteLine(pro2.PriceTag());

            //ImportedProduct impo = (ImportedProduct) pro; //Duas formas de fazer um downcasting
            ImportedProduct impo = pro as ImportedProduct; //Outra forma de fazer o downcasting

            System.Console.WriteLine(impo.TotalPrice());
        }
        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 = 1; i <= n; i++)
            {
                Console.WriteLine($"Product #{i} data: ");
                Console.Write("Common, used or imported (c/u/i)? ");
                string import = Console.ReadLine();
                Console.Write("Name: ");
                string name = Console.ReadLine();
                Console.Write("Price: ");
                double price = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
                if (import == "i")
                {
                    Console.Write("Custom fee: ");
                    double fee = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
                    list.Add(new ImportedProduct(name, price, fee));
                    Product Import = new ImportedProduct();
                    Import.PriceTag(import);
                }
                else if (import == "u")
                {
                    Console.Write("Manufacture date (DD/MM/YYYY): ");
                    DateTime manufacture = DateTime.Parse(Console.ReadLine());
                    list.Add(new UsedProduct(name, price, manufacture));
                    Product used = new UsedProduct();
                    used.PriceTag(import);
                }
                else
                {
                    list.Add(new Product(name, price));
                    Product product = new Product();
                    product.PriceTag(import);
                }
            }

            Console.WriteLine();
            foreach (Product product in list)
            {
                Console.WriteLine(product);
            }

            Console.WriteLine();
        }