The Atom, Bond, and Molecule classes

The atoms and the bonds are represented in the application by the Java ™ classes Atom and Bond . These classes obey the JavaBeans™ conventions, for example, the Atom class has a property called symbol which represents the abbreviated symbol of the element; this property can be accessed through the methods setSymbol and getSymbol .

The Atom class

The following code example shows part of the Atom class.
Bean property in the Atom class
/**
 * A class that represents an atom.
 */ 
public class Atom
{

...

  private String symbol;
  
   public String getSymbol()
  {
    return symbol;
  }

  public void setSymbol(String symbol)
  {
    this.symbol = symbol;
  }

  
}
The Atom class has also a name property (the name of the element) , and an id property, which identifies the atom in the molecule.

The Bond class

The Bond class has two properties firstAtom and secondAtom which contain the identifiers of the two atoms linked by the bond, and also a type property which can have the values single or double .

The Molecule class

A molecule is represented by an instance of the class Molecule . A molecule contains a list of atoms and a list of bonds.
The following code example shows the Molecule class.
Arrays of objects in the Molecule class
public class Molecule
{
  private ArrayList atoms = new ArrayList();
  private ArrayList bonds = new ArrayList();
  
  public Atom[] getAtoms()
  {
    return (Atom[]) atoms.toArray(new Atom[0]);
  }
  
  public Bond[] getBonds()
  {
    return (Bond[]) bonds.toArray(new Bond[0]);
  }
  
}