Java Reference
In-Depth Information
-
Write a static function
boolean
bump(Atom a, Atom b)
that takes as
arguments two atoms
a
and
b
, and return
true
if and only if the
distance between their centers is strictly less than the sum of their
radii (this will represent a collision between two atoms). This function
shall be defined inside the class
Atom
.
SOLUTION:
Program 11.2
Class
Atom
with the
bump
predicate
public class
Atom
{
Point3D center
;
double
radius ;
public static final double
H RADIUS = 1 . 2 ;
public static final double
O RADIUS = 1 . 5 ;
public
Atom (
double
x,
double
y,
double
z,
double
rad
)
{
this
.center=
new
Point3D (x , y , z ) ;
this
.radius=rad;
public static boolean
bump ( Atom a , Atom b )
{
return
Point3D . distance (a. center
, b. center )
<
a. radius + b. radius ;
}
}
// Temporary class; Shall be enhanced next
-
Write a class
Molecule
that allows us to define a 3D molecule as an
array of atoms, and provide the class with a constructor that takes as
argument a reference to this array.
SOLUTION:
Program 11.3
Class
Molecule
public class
Molecule
{
Atom [ ] atoms ;
public
Molecule ( Atom []
t)
{
this
. atoms = t ;
}
}
-
Using a new class
Test
, write a program that builds a water molecule
H20 with its oxygen atom located at (0
,
0
.
4
,
0) and the two hydrogen
atoms located at (0
.
76
,
−
0
.
19
,
0) and (
−
0
.
76
,
−
0
.
19
,
0) (units still
being angstrom).
Search WWH ::
Custom Search