KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > chemistry > Atom


1 package JSci.chemistry;
2
3 import JSci.physics.*;
4 import JSci.physics.particles.*;
5
6 /**
7 * A class representing atoms.
8 * @version 0.2
9 * @author Mark Hale
10 */

11 public class Atom extends Particle {
12         /**
13         * Shell.
14         */

15         private Lepton shell[];
16         private final int shellSize;
17         /**
18         * Nucleus.
19         */

20         private Nucleon nucleus[];
21         private final int nucleusSize;
22         /**
23         * Constructs an atom.
24         */

25         public Atom(Element e) {
26                 shellSize = e.getAtomicNumber();
27                 nucleusSize = e.getMassNumber();
28         }
29         /**
30         * Returns the nucleus.
31         */

32         public Nucleon[] getNucleus() {
33                 if(nucleus == null) {
34                         nucleus = new Nucleon[nucleusSize];
35                         int i;
36                         for(i=0; i<shellSize; i++)
37                                 nucleus[i] = new Proton();
38                         for(; i<nucleusSize; i++)
39                                 nucleus[i] = new Neutron();
40                 }
41                 return nucleus;
42         }
43         /**
44         * Returns the electron shell.
45         */

46         public Lepton[] getShell() {
47                 if(shell == null) {
48                         shell = new Lepton[shellSize];
49                         for(int i=0; i<shellSize; i++)
50                                 shell[i] = new Electron();
51                 }
52                 return shell;
53         }
54         /**
55         * Binds this atom with another.
56         */

57         public Molecule bind(Atom a) {
58                 return new Molecule(this, a);
59         }
60 }
61
62
Popular Tags