Java Reference
In-Depth Information
A graphical user interface allows the responsible technician to open and
close every single pump using a slider button. The value of the slider is auto-
matically set to zero when the paint transfer is inhibited. The class diagram
of the car painting work cell simulator is reported in Figure 13.8.
13.4.3
Implementation
Class
Tank
simulates the behaviour of a colour tank. It implements five
public methods:
■
void push(int microVol, double c[])
receives a certain amount of paint of a
given colour and updates the current level and tonality of the paint in
the tank. The colour is expressed as a vector of double values in order to
maintain good precision of the colour tonality after mixing with a different
colour. This method is invoked by the input pump.
void pull(int microVol)
updates the current paint level in the tank by sub-
tracting the micro-volume indicated as argument. This method is invoked
by the output pump.
■
public int getLevel()
,
public int getResidue()
and
public double[] getColor()
return the current paint level in the tank, the difference between the tank
capacity and the current level, and the paint colour. The first two
methods are used by the pump to determine if the upstream tank is empty
or the downstream tank is full.
■
package
scada.simulator;
public class
Tank {
private double
[] color
#
{0.0, 0.0, 0.0};
// colour tonality in RGB scale
private int
capacity
#
100000;
// tank capacity in millilitres
private int
level; // current level in millilitres
public
Tank(
int
color[],
int
percentLevel){
for
(
int
i
#
0; i<3; i
!!
)
this
.color[i]
#
color[i];
this
.level
#
capacity / 100 * percentLevel;
}
public int
getLevel() {
return
level; }
public int
getResidue() {
return
capacity-level; }
public double
[] getColor() {
return
color; }
// the push() method receives a quantity of paint of a
// given colour and updates the current level and colour
// tonality
public void
push(
int
microVol,
double
c[]) {
if
(c !
#
null
) {
// the amount of paint in the tank for each tonality
double
qr
#
color[0]*level/(color[0]
!
color[1]
!
color[2]);
double
qg
#
color[1]*level/(color[0]
!
color[1]
!
color[2]);