You are on page 1of 3

Tank,aModelofStorage

Description:

Thismodelisatankwithaninflowandanoutflow.Theinflowisconstant,the
outflowisproportionaltoonthequantityinthetank.Finally,whentheinflowis
equaltotheoutflow,thequantitywillstaythesame.


Examples:
Kitchensink
Steadyleaffall
andcreatures
decomposing
them.
Code:tank.java Variables:
J=inflow
Q=storedquantity.

Equations:
K*Q=outflow
DQ=JK*Q=changeduringatimeincrement

Simulation:
ThegraphshowsthechangeofQoveratimeperiod.

"Whatif"Experiments:

Thinkaboutasinkthatisabouthalffilledwithwater:
Whatchangesifyoustartwith100litersofwaterinthesinkinsteadofoneliter?
Whathappensifyoucutoffthefaucetafter96hours?
StudytheeffectoftheoutflowcoefficientK.
//tank.java
//tankwithinflowandoutflow
//adaptedfromaprograminbasicbyH.T.Odum&E.Odum,1994

importjava.applet.*;
importjava.awt.*;

publicclasstankextendsApplet
{

Labelprompt1,prompt2,prompt3;
TextFieldinput1,input2,input3;
ChoicechooseEvent;
ButtondrawButton;
GridBagLayoutgbLayout;
GridBagConstraintsgbConstraints;
doubleq,k0,k,t1,qi,dq,j0,j;
inta,t,ti;

publicvoidinit()
{
prompt1=newLabel("StartvalueforQ:");
input1=newTextField("10",5);

prompt2=newLabel("KOutflowcoefficient:");
input2=newTextField("5",5);

prompt3=newLabel("t_1:");
input3=newTextField("96",4);

chooseEvent=newChoice();
chooseEvent.addItem("Nochangeofinflow/outflow");
chooseEvent.addItem("Stopinflowatt_1");
chooseEvent.addItem("Stopoutflowatt_1");
chooseEvent.addItem("Doubleinflowatt_1");
chooseEvent.addItem("Doubleoutflowatt_1");

drawButton=newButton("Draw");

add(prompt1);
add(input1);
add(drawButton);
add(prompt2);
add(input2);
add(prompt3);
add(input3);
add(chooseEvent);
}

publicbooleanaction(Evente,Objecto)
{
q=(float)Integer.parseInt(input1.getText());
k0=0.01f*(float)Integer.parseInt(input2.getText());
t1=Integer.parseInt(input3.getText());

if(e.targetinstanceofChoice)
a=chooseEvent.getSelectedIndex();

repaint();
returntrue;
}

publicvoidpaint(Graphicsg)
{
g.drawRect(0,90,320,250);
t=0;
j0=4;
j=j0;
k=k0;

while(t<320){
ti=t+1;
if(ti>=t1){
switch(a){
case0:break;
case1:j=0;break;
case2:k=0;break;
case3:j=j0*2;break;
case4:k=k0*2;break;
default:break;
}
}
dq=jk*q;
qi=q+dq;
g.setColor(Color.blue);
g.drawLine((int)t,(int)(340q),(int)ti,(int)(340qi));
t=ti;q=qi;
}
}
}
//ManuelBasler&E.Ortega,October25th2000/

You might also like