static void Main(string[] args)
        {
            List<Computer> catalog = new List<Computer>();
            List<Components> components1 = new List<Components>();

            Components monitor = new Components("Monitor: Samsung", 150);
            components1.Add(monitor);
            Components mouse = new Components("Mouse: Canyon", 20);
            components1.Add(mouse);
            Components hdd = new Components("HDD: Corsair", 60);
            components1.Add(hdd);

            Computer pc1 = new Computer("MyHomePC", components1, 2000.00m);
            catalog.Add(pc1);

            List<Components> components2 = new List<Components>();
            components2.Add(new Components("Monitor: Lenovo", 50));
            components2.Add(new Components("Video Card: GForce", 10));
            components2.Add(new Components("HDD: HP", 20));
            Computer pc2 = new Computer("Office PC", components2, 1534.40m);
            catalog.Add(pc2);

            var sortedByPrize = catalog.OrderBy(c => c.Price).ToList();
            foreach (var pc in catalog)
            {
                Console.WriteLine(pc);
                Console.WriteLine();
            }
        }
        static void Main()
        {
            List<Component> components = new List<Component>();
            components.Add(new Component("HDD", 234.43m));
            components.Add(new Component("CPU", 120.45m));
            components.Add(new Component("RAM", 45.50m, "2 GB, DDR"));
            Computer pc = new Computer("HP", components);
            List<Computer> catalog = new List<Computer>();
            catalog.Add(pc);
            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 pc1 = new Computer("Lenovo", components1);
            catalog.Add(pc1);
            List<Component> components2 = new List<Component>();
            components2.Add(new Component("CPU", 134));
            components2.Add(new Component("RAM", 123.65m, "4GB"));
            Computer pc2 = new Computer("Sony", components2);
            catalog.Add(pc2);

            var catalogSort = catalog.OrderBy(x => x.Price);

            foreach (var item in catalogSort)
            {
                Console.WriteLine(item);
            }
        }
 public static decimal Calculate(Computer computer)
 {
     var components = computer.Components;
     decimal price = 0;
     foreach (var component in components)
     {
         price += component.Price;
     }
     return price;
 }
        static void Main()
        {
            Console.WriteLine("Enter pc Name");
            string name = "nasaPC";
            Computer nasaPC = new Computer(name, "Intel I7", 2312, "NVIDIA", 2132, "motherboard", 232);
            Console.WriteLine("Enter a price!");
            int price = 2000;
            
            
            Component VGA = new Component("graphicCard", (decimal)658, "nVIDIA");

            
            Console.WriteLine(nasaPC.ToString());

        }
Example #5
0
        static void Main(string[] args)
        {
            // Use "." instead of "," for numbers.
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";
            System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

            try
            {
                var motherboard1 = new Component(44.80m, "Cheap Motherboard");
                var motherboard2 = new Component(85.50m, "Deluxe Motherboard");
                var cpu1 = new Component(81.20m, "CPU 2 cores");
                var cpu2 = new Component(190.20m, "CPU 4 cores");
                var graphics1 = new Component(130m, "Fancy graphics");
                var psu1 = new Component(75.35m, "Powerful PSU");
                var psu2 = new Component(30.90m, "Second-hand PSU");

                var pc1 = new Computer("PC1", motherboard1, cpu2, psu1);
                var pc2 = new Computer("PC2", motherboard2, cpu1, graphics1, psu1);
                var pc3 = new Computer("PC3", motherboard1, psu2);
                var pc4 = new Computer(psu1, graphics1, cpu1);

                List<Computer> list = new List<Computer>();
                list.Add(pc1);
                list.Add(pc2);
                list.Add(pc3);
                list.Add(pc4);
                list.Sort((x, y) => x.Price.CompareTo(y.Price));

                foreach (var item in list)
                {
                    item.Print();
                }
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        static List<Computer> AddComputers()
        {
            List<Computer> computers = new List<Computer>();
            string ch = null;

            do
            {
                Console.Write("Enter the computer name: ");
                string name = Console.ReadLine();

                List<Component> components = AddComponents();

                Computer computer = new Computer(name, components);
                computers.Add(computer);

                Console.Write("\nDo you want to add another computer (y/n)?");
                ch = Console.ReadLine();
                Console.WriteLine();
            }
            while (ch != "n" && ch != "N");

            return computers;
        }