Example #1
0
 public static double SumMass(Atom[] atoms)
 {
     double sum = 0;
     foreach (Atom a in atoms)
     {
         sum += a.Mass;
     }
     return sum;
 }
Example #2
0
 public Molecule(Atom[] atoms) : base(null, null, -1)
 {
     if (atoms == null || atoms.Length < 2)
     {
         throw new ArgumentException("At least 2 atomes in a molecule");
     }
     Name = Symbol = GetChemicalFormula(atoms);
     Mass = SumMass(atoms);
     Atoms = atoms;
 }
Example #3
0
 public static string GetChemicalFormula(Atom[] atoms)
 {
     var dico = new Dictionary<string, int>();
     foreach (Atom atom in atoms)
     {
         if (dico.ContainsKey(atom.Symbol))
             dico[atom.Symbol]++;
         else
             dico[atom.Symbol] = 1;
     }
     var formula = "";
     foreach (string symbol in dico.Keys)
     {
         formula += symbol;
         int count = dico[symbol];
         if (count > 1) formula += count;
     }
     return formula;
 }
 public Molecule Create(Atom[] atoms)
 {
     return new Molecule(atoms);
 }