Exemplo n.º 1
0
        static void Main(string[] args)
        {
            List<Computer> computers = new List<Computer>();

            Component pc1mb =  new Component("Asus AK-47", "mini form factor", 334m);
            Component pc2mb = new Component("Gigabyte AZ32", "mini form factor", 144m);
            Component pc3mb =  new Component("My motherboard", 112m);

            Component pc1processor = new Component("i7 2345", "64 cores", 234m);
            Component pc2processor = new Component("i5 2345", "32 cores", 134m);
            Component pc3processor = new Component("i3 2200", 104m);

            Component pc1ram = new Component("32GB", "DDR5", 200m);
            Component pc2ram = new Component("16GB", "DDR5",  100m);
            Component pc3ram = new Component("8GB", 80m);

            Computer PC1 = new Computer("ASUS", pc1ram, pc1mb, pc1processor);
                
            Computer PC2 = new Computer("GigaBUUUG",pc2ram, pc2mb, pc2processor);

            Computer PC3 = new Computer("Handmade", pc3ram, pc3mb, pc3processor);

            computers.Add(PC1);
            computers.Add(PC2);
            computers.Add(PC3);

            computers = computers.OrderBy(o => o.PcPrice).ToList();

            foreach (var computer in computers)
            {
                Console.WriteLine(computer);
                Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            List<Computer> catalog = new List<Computer>();
            List<Component> components = new List<Component>();
            components.Add(new Component("HDD", 250.32m));
            components.Add(new Component("CPU", 560.45m));
            components.Add(new Component("RAM", 103.50m));
            Computer lenovo = new Computer("Lenovo", components);

            List<Component> components1 = new List<Component>();
            components1.Add(new Component("CPU", 231));
            components1.Add(new Component("Motheboard", 351));
            components1.Add(new Component("Graphics card", 351));
            Computer mac = new Computer("Mac", components1);

            List<Component> components2 = new List<Component>();
            components2.Add(new Component("CPU", 134));
            components2.Add(new Component("RAM", 123.65m, "4GB"));
            Computer sony = new Computer("Sony", components2);

            catalog.Add(lenovo);
            catalog.Add(mac);
            catalog.Add(sony);

            var sortCatalog = catalog.OrderBy(computer => computer.Price);

            foreach (var computer in sortCatalog)
            {
                Console.WriteLine(computer);
            }
        }
        private decimal Calculate(Computer computer)
        {
            var components = computer.Components;
            decimal price = components.Sum(component => component.Price);

            return price;
        }