Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var comp1 = new Computer("admin", "bla", new CPU("Intel", 3000), new HDD("IBM", 500), new RAM("IBM", 1000));
            var comp2 = new Computer("admin2", "bla", new CPU("IBM", 3000), new HDD("IBM", 750), new RAM("IBM", 2000));

            Console.WriteLine("COMPUTERS:");
            Console.WriteLine(comp1.ToString());
            Console.WriteLine(comp2.ToString());

            Console.WriteLine("\nAttempt to add computers");
            try
            {
                var comp3 = comp1 + comp2;
            }
            catch(ComputersCompatibilityException e)
            {
                Console.WriteLine(e.Message);
            }

            Computer clonedComp1 = comp1.DeepClone();
            Computer superComp = clonedComp1 + comp1;

            Console.WriteLine("\nSumming the comp1 and its copy");
            Console.WriteLine(superComp.ToString());

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public Computer DeepClone()
        {
            var comp = new Computer();
            comp._cpus = new List<CPU>();
            foreach (var item in _cpus)
            {
                comp._cpus.Add(new CPU(String.Copy(item.Vendor), item.Value));
            }

            comp._hdds = new List<HDD>();
            foreach (var item in _hdds)
            {
                comp._hdds.Add(new HDD(String.Copy(item.Vendor), item.Value));
            }

            comp._rams = new List<RAM>();
            foreach (var item in _rams)
            {
                comp._rams.Add(new RAM(String.Copy(item.Vendor), item.Value));
            }

            comp._hostName = String.Copy(_hostName);
            comp._description = String.Copy(_description);

            return comp;
        }
Ejemplo n.º 3
0
 private static bool CheckСompatibility(Computer comp1, Computer comp2)
 {
     if (String.Compare(comp1.Cpu.Vendor, comp2.Cpu.Vendor, true) == 0 &&
         String.Compare(comp1.Hdd.Vendor, comp2.Hdd.Vendor, true) == 0 &&
          String.Compare(comp1.Ram.Vendor, comp2.Ram.Vendor, true) == 0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 4
0
 public void AddComputer(Computer comp)
 {
     if (CheckСompatibility(this, comp))
     {
         _cpus.Add(comp.Cpu);
         _hdds.Add(comp.Hdd);
         _rams.Add(comp.Ram);
         _description = String.Format("{0} / {1}", _description, comp.Description);
         _hostName = String.Format("{0} + {1}", _hostName, comp.HostName);
     }
     else
     {
         throw new ComputersCompatibilityException("Vendors are different!");
     }
 }