Sludge source code

//Sludge.java
//Michael E. Shultz
//Java Programming
import java.applet.*;
import java.awt.*;

public class Sludge extends Applet
{
//Properties go here
Label lblTitle1 = new Label("Michael E. Shultz's");
Label lblTitle2 = new Label("Analyses Calculator");
Label lblBlank = new Label("Blank analysis in ppb ");
Label lblSampleA = new Label("Sample A analysis in ppb ");
Label lblSampleB = new Label("Sample B analysis in ppb ");
Label lblDiffPct = new Label("Percent difference ");
Label lblSpike = new Label("Spike analysis in ppb ");
Label lblSpikeAmt = new Label("Amount of spike in ppb ");
Label lblSpikePct = new Label("Percent spike recovery ");
Label lblConc = new Label("Concentration in n:1 ");
Label lblResult = new Label("Result in ppb ");
Label lblPctSolid = new Label("Sample decimal percent solids ");
Label lblDryWt = new Label("Result in dry wt. mg/kg ");

float fBlank;
float fSample;
float fDiffPct;
float fSpike;
float fSpikePct;
float fSpikeAmt;
float fPctSolid;
float fConc;
float fResult;
float fDryWt;

//GUI elements go here
TextField blank = new TextField(10);
TextField sampleA = new TextField(10);
TextField sampleB = new TextField(10);
TextField diffPct = new TextField(10);
TextField spike = new TextField(10);
TextField spikeAmt = new TextField(10);
TextField spikePct = new TextField(10);
TextField conc = new TextField(10);
TextField result = new TextField(10);
TextField pctSolid = new TextField(10);
TextField dryWt = new TextField(10);
Button Calculate = new Button("Calculate");
Button Clear = new Button("Clear");
Button Default = new Button("Default Values");

public void init()
{
//add the GUI elements here
add(lblTitle1);
add(lblTitle2);
add(lblBlank);
add(blank);
add(lblSampleA);
add(sampleA);
add(lblSampleB);
add(sampleB);
add(lblDiffPct);
add(diffPct);
diffPct.setEditable(false);
add(lblSpike);
add(spike);
add(lblSpikeAmt);
add(spikeAmt);
add(lblSpikePct);
add(spikePct);
spikePct.setEditable(false);
add(lblConc);
add(conc);
add(lblPctSolid);
add(pctSolid);
add(lblResult);
add(result);
result.setEditable(false);
add(lblDryWt);
add(dryWt);
dryWt.setEditable(false);
add(Calculate);
add(Clear);
add(Default);
blank.requestFocus();
}

public boolean action(Event thisEvent, Object thisObject)
{
if (thisEvent.target == Calculate)
CalcNumbers();
else if (thisEvent.target == Clear)
ClearNumbers();
else if (thisEvent.target == Default)
DefaultValues();
return true;
}

public void ClearNumbers()
{
blank.setText("");
sampleA.setText("");
sampleB.setText("");
diffPct.setText("");
spike.setText("");
spikeAmt.setText("");
spikePct.setText("");
conc.setText("");
result.setText("");
pctSolid.setText("");
dryWt.setText("");
blank.requestFocus();
fSample = 0F;
}

public void DefaultValues()
{
blank.setText("1.2");
sampleA.setText("27.3");
sampleB.setText("24.1");
diffPct.setText("");
spike.setText("33.9");
spikeAmt.setText("10");
spikePct.setText("");
conc.setText("20");
result.setText("");
pctSolid.setText(".041");
dryWt.setText("");
Calculate.requestFocus();
}

public void CalcNumbers()
{
//processing goes here
fSample = 0F;
fBlank = toFloat(blank.getText() );
String sSampleA = sampleA.getText();
String sSampleB = sampleB.getText();
if (!(sSampleA.equals("")) && !(sSampleB.equals("")))
{
fSample = ((toFloat(sSampleA) + toFloat(sSampleB)) / 2);
fDiffPct = ((toFloat(sSampleA) - toFloat(sSampleB)) / fSample) *100;
diffPct.setText(fDiffPct + "");
}
else if (!(sSampleA.equals("")) && sSampleB.equals(""))
{
fSample = toFloat(sSampleA);
diffPct.setText("");
}
else if (sSampleA.equals("") && !(sSampleB.equals("")))
{
fSample = toFloat(sSampleB);
diffPct.setText("");
}
String sSpike = spike.getText();
String sSpikeAmt = spikeAmt.getText();
if (!(sSpike.equals("")) && !(sSpikeAmt.equals("")))
{
fSpike = toFloat(sSpike);
fSpikeAmt = toFloat(sSpikeAmt);
fSpikePct = (fSpike / (fSample + fSpikeAmt )) * 100;
spikePct.setText(fSpikePct + "");
}
else
{
spikePct.setText("");
}
fConc = toFloat(conc.getText() );
fResult = (fSample - fBlank) * fConc;
result.setText(fResult + "");
String sPctSolid = pctSolid.getText();
if (!(sPctSolid.equals("")))
{
fPctSolid = toFloat(sPctSolid);
fDryWt = fResult / (fPctSolid * 1000);
dryWt.setText(fDryWt + "");
}
else
{
dryWt.setText("");
}
blank.requestFocus();
}

public float toFloat (String fString)
{
Float flvalue = new Float (fString);
return flvalue.floatValue();
}
}

Back to Sludge

Top

© Copyright 2001 by Michael E. Shultz, All rights reserved