public double getAverageMass() {
    double mass = 0;
    Iterator<Isotope> isotopeIterator = isotopes.iterator();
    Isotope isotope;

    if (isNaturallyOccurring()) {
      while (isotopeIterator.hasNext()) {
        isotope = isotopeIterator.next();
        mass += isotope.getMass() * isotope.getAbundance();
      }
      return mass;
    }

    while (isotopeIterator.hasNext()) {
      isotope = isotopeIterator.next();
      mass += isotope.getMass();
    }
    return mass / isotopes.size();
  }
  public double getMonoisotopicMass() {
    if (isotopes.isEmpty()) return 0;

    Iterator<Isotope> isotopeIterator = isotopes.iterator();
    Isotope isotope;
    Isotope mostAbundant = isotopeIterator.next();

    while (isotopeIterator.hasNext()) {
      isotope = isotopeIterator.next();
      if (isotope.getAbundance() > mostAbundant.getAbundance()) {
        mostAbundant = isotope;
      }
    }

    return mostAbundant.getMass();
  }
  public double getVariance() {
    double average = getAverageMass();
    double difference;
    double variance = 0;
    double totalAbundance = 0;

    Iterator<Isotope> isotopeIterator = isotopes.iterator();
    Isotope isotope;
    while (isotopeIterator.hasNext()) {
      isotope = isotopeIterator.next();
      difference = isotope.getMass() - average;
      variance += difference * difference * isotope.getAbundance();
      totalAbundance += isotope.getAbundance();
    }

    return variance / totalAbundance;
  }