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
.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; } }
Atom
class has also a name
property
(the name of the element) , and an id
property,
which identifies the atom in the molecule.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
.Molecule
.
A molecule contains a list of atoms and a list of bonds.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]); } }