static void Main(string[] args) { Computer comp = new Computer("PC 1"); comp.AddComponent("CPU", 300m); comp.AddComponent("GFX", 500m); comp.AddComponent("RAM", 100m); Console.WriteLine(comp.ToString()); }
static void Main() { Console.OutputEncoding = Encoding.Unicode; List <Component> components = new List <Component>(); components.Add(new Component("Motherboard", 90)); components.Add(new Component("CPU", 120.45m)); components.Add(new Component("RAM", 45.50m, "8 GB")); // components.Add(new Component(" ", 12)); // Empty name => Exception // components.Add(new Component("HDD", -1.1m)); // Negative price => Exception Computer pc = new Computer("HP", components); Console.WriteLine(pc); pc.AddComponent(new Component("added later", 1)); // Using method that allows addition of components Console.WriteLine(pc); // List<Component> emptyComponentsList = new List<Component>(); // Computer pcWithoutComponents = new Computer("Ooops", emptyComponentsList); // Empty components list on creation => Exception List <Computer> catalog = new List <Computer>(); catalog.Add(pc); List <Component> componentsList4 = new List <Component>(); componentsList4.Add(new Component("GPU", 1125.5m)); componentsList4.Add(new Component("CPU", 900)); catalog.Add(new Computer("Expensive", componentsList4)); List <Component> componentsList2 = new List <Component>(); componentsList2.Add(new Component("DVD", 15.99m)); componentsList2.Add(new Component("GPU", 255.1m)); catalog.Add(new Computer("Cheap", componentsList2)); List <Component> componentsList3 = new List <Component>(); componentsList3.Add(new Component("RAM", 52.19m)); componentsList3.Add(new Component("SSD", 550)); catalog.Add(new Computer("Average", componentsList3)); catalog.Sort(); // Icomparable interface implemented on Computer class foreach (var computer in catalog) { Console.WriteLine(computer); } }
static void Main() { Computer pc1 = new Computer("Boiko Prezident"); pc1.AddComponent("Video Card", 250.54, "Lada"); pc1.AddComponent("Sound Card", 25.54, "Lada"); pc1.AddComponent("Processor", 350, "Intel i7 mn qk"); Computer pc2 = new Computer("Pravetz 343TT"); pc2.AddComponent("Video Card", 250.54, "Lada"); pc2.AddComponent("Sound Card", 125.54, "Lada"); pc2.AddComponent("Processor", 350, "Intel i7 mn qk"); Computer pc3 = new Computer("Stamat 1000"); pc3.AddComponent("Video Card", 20.54, "Lada"); pc3.AddComponent("Sound Card", 25.54, "Lada"); pc3.AddComponent("Processor", 350, "Intel i7 mn qk"); List<Computer> computers = new List<Computer>(); computers.Add(pc1); computers.Add(pc2); computers.Add(pc3); computers = computers.OrderBy(x => x.Price).ToList(); foreach (var computer in computers) { Computer.Print(computer); } }
public static void Main(string[] args) { List<Component> components = new List<Component>(); components.Add(new Component("HDD", 120)); components.Add(new Component("RAM", 140)); Computer firstPc = new Computer("HP", components); Computer secondPc = new Computer("DELL"); secondPc.AddComponent(new Component("CPU", 500)); secondPc.AddComponent(new Component("GPU", 1000)); List<Computer> computers = new List<Computer>(); computers.Add(firstPc); computers.Add(secondPc); computers.Sort(); foreach (var item in computers) { item.Print(); Console.WriteLine(); } }
static void Main() { Console.OutputEncoding = Encoding.Unicode; List<Component> components = new List<Component>(); components.Add(new Component("Motherboard", 90)); components.Add(new Component("CPU", 120.45m)); components.Add(new Component("RAM", 45.50m, "8 GB")); // components.Add(new Component(" ", 12)); // Empty name => Exception // components.Add(new Component("HDD", -1.1m)); // Negative price => Exception Computer pc = new Computer("HP", components); Console.WriteLine(pc); pc.AddComponent(new Component("added later", 1)); // Using method that allows addition of components Console.WriteLine(pc); // List<Component> emptyComponentsList = new List<Component>(); // Computer pcWithoutComponents = new Computer("Ooops", emptyComponentsList); // Empty components list on creation => Exception List<Computer> catalog = new List<Computer>(); catalog.Add(pc); List<Component> componentsList4 = new List<Component>(); componentsList4.Add(new Component("GPU", 1125.5m)); componentsList4.Add(new Component("CPU", 900)); catalog.Add(new Computer("Expensive", componentsList4)); List<Component> componentsList2 = new List<Component>(); componentsList2.Add(new Component("DVD", 15.99m)); componentsList2.Add(new Component("GPU", 255.1m)); catalog.Add(new Computer("Cheap", componentsList2)); List<Component> componentsList3 = new List<Component>(); componentsList3.Add(new Component("RAM", 52.19m)); componentsList3.Add(new Component("SSD", 550)); catalog.Add(new Computer("Average", componentsList3)); catalog.Sort(); // Icomparable interface implemented on Computer class foreach (var computer in catalog) { Console.WriteLine(computer); } }
static void Main() { Computer asus = new Computer("Asus M12AD-RO016D", new List <Component> { new Component("Processor", "Intel® Core™ i5-4460S 2.90GHz", 700.00m), new Component("HDD", "1TB", 200.00m), new Component("RAM", "4GB", 150.00m), new Component("Graphic card", "NVIDIA GeForce GTX 745 4GB", 459.00m), }); Computer lenovo = new Computer("Lenovo IdeaCentre B50-30 All-In-One", new List <Component> { new Component("Processor", "Intel® Core™ i5-4460T 1.90GHz", 1200.00m), new Component("HDD", "1TB", 278.00m), new Component("RAM", "8GB", 477.90m), new Component("Graphic card", "Intel® HD Graphics 4600", 999.00m), }); Computer apple = new Computer("Apple Mac Pro", new List <Component> { new Component("Processor", " Intel® Xeon® E5-1650 v2", 3200.00m), new Component("HDD", 1240.00m), new Component("RAM", "16GB", 700.90m), new Component("Graphic card", "FirePro™ D500", 2900.00m), }); apple.AddComponent(new Component("SSD", "256GB", 1199.00m)); List <Computer> computers = new List <Computer>() { asus, lenovo, apple }; computers.Sort((a, b) => a.Price <b.Price ? -1 : a.Price> b.Price ? 1 : 0); foreach (var computer in computers) { Console.WriteLine(computer); } }