/** * A table used to store and look up elements. * The periodic table organizes elements by their atomic numbers. * Internally, an array representation is used to allow for * speedy access. We are assuming that the number and order of * elements is not going to change. * @author Paul Gestwicki */ public class PeriodicTable { /** * The internal representation of the periodic table. * The array is indexed by atomic number. */ private Element[] table; /** * Construct a new periodic table. * @param numberOfElements the number of elements that can be * stored in the periodic table */ public PeriodicTable(int numberOfElements) { table = new Element[numberOfElements]; } /** * Add an element to the periodic table. * @param e the element to add */ public void addElement(Element e) { table[e.getAtomicNumber()] = e; } /** * Fetch an element from the table by its atomic number. * @param atomicNumber the atomic number of the element that * is being retrieved from the table. * @return the element with the given atomic number, or null if it * has not been added yet (see {@link #addElement(Element)}). */ public Element getElement(int atomicNumber) { return table[atomicNumber]; } }