<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.awt.*;

public class ExampleScreen extends Panel {

  private double li, hi;
  private int nli, nhi, yli, yhi;
  private Label yli_probLabel, yhi_probLabel, tli_probLabel, thi_probLabel;
  private Label nliLabel, nhiLabel, yliLabel, yhiLabel, tliLabel, thiLabel;
  private double chiSquared;
  private TextArea ta;

  public ExampleScreen() {
    Panel p=new Panel();

    p.setLayout(new GridLayout(4, 4));

    p.add(new Label("College Grad?"));
    p.add(new Label("Low Income"));
    p.add(new Label("High Income"));
    p.add(new Label("Total"));

    p.add(new Label("No"));
    p.add(new Label(BUtil.dtos(ChiSquared.NLI_PROB)));
    p.add(new Label(BUtil.dtos(ChiSquared.NHI_PROB)));
    p.add(new Label("1.0"));

    p.add(new Label("Yes"));
    p.add(yli_probLabel=new Label());
    p.add(yhi_probLabel=new Label());
    p.add(new Label("1.0"));

    p.add(new Label("Total"));
    p.add(tli_probLabel=new Label());
    p.add(thi_probLabel=new Label());
    p.add(new Label("1.0"));

    setLayout(new BorderLayout());
    setBackground(Color.lightGray);
    add("North", p);

    Panel ap=new Panel();

    p=new Panel();
    p.setLayout(new GridLayout(4, 4));

    p.add(new Label("College Grad?"));
    p.add(new Label("Low Income"));
    p.add(new Label("High Income"));
    p.add(new Label("Total"));

    p.add(new Label("No"));
    p.add(nliLabel=new Label());
    p.add(nhiLabel=new Label());
    p.add(new Label(ChiSquared.NUM_SAMPLES_PER_ROW+""));

    p.add(new Label("Yes"));
    p.add(yliLabel=new Label());
    p.add(yhiLabel=new Label());
    p.add(new Label(ChiSquared.NUM_SAMPLES_PER_ROW+""));

    p.add(new Label("Total"));
    p.add(tliLabel=new Label());
    p.add(thiLabel=new Label());
    p.add(new Label(ChiSquared.NUM_SAMPLES+""));

    ta=new TextArea(6, 50);
    ta.setBackground(Color.lightGray);
    ta.setEditable(false);

    ap.setLayout(new BorderLayout());
    ap.add("South", p);
    ap.add("Center", ta);

    add("Center", ap);

    p=new Panel();
    p.setBackground(Color.gray);
    p.add(new Button("Continue"));

    add("South", p);
  }

  public void setProbabilities(double collegeGradLowIncomeProbability) {
    li=collegeGradLowIncomeProbability;
    hi=1-li;

    yli_probLabel.setText(BUtil.dtos(li));
    yhi_probLabel.setText(BUtil.dtos(hi));

    tli_probLabel.setText(BUtil.dtos((ChiSquared.NLI_PROB+li)/2));
    thi_probLabel.setText(BUtil.dtos((ChiSquared.NHI_PROB+hi)/2));
  }

  public void generate() {
    int i;

    nli=0;
    nhi=0;
    yli=0;
    yhi=0;

    for (i=0; i&lt;ChiSquared.NUM_SAMPLES_PER_ROW; i++) {
      if (Math.random() &gt; ChiSquared.NLI_PROB)
        nhi++;
      else nli++;

      if (Math.random() &gt; li)
        yhi++;
      else yli++;
    }

    nliLabel.setText(nli+"");
    nhiLabel.setText(nhi+"");

    yliLabel.setText(yli+"");
    yhiLabel.setText(yhi+"");

    tliLabel.setText(nli+yli+"");
    thiLabel.setText(nhi+yhi+"");

    chiSquared=ChiSquared.NUM_SAMPLES*
               (double)(nli*yhi-nhi*yli)*(nli*yhi-nhi*yli)/
               ((double)(nli+nhi)*(yli+yhi)*(nli+yli)*(nhi+yhi));
  }

  public void fillTextArea() {
    ta.setText("");
    ta.appendText("In the table above, the probabilities entered in the\n");
    ta.appendText("previous screen can be found.  Below is a table randomly\n");
    ta.appendText("generated from these probabilities.  Although it is clearly\n");
    ta.appendText("based upon the probabilities in the table above, note that\n");
    ta.appendText("there are some random variations, so the probabilities observed\n");
    ta.appendText("are not exactly the probabilities from the table.\n\n");
    ta.appendText("The Chi-Square statistic for the table below is "+BUtil.dtos(chiSquared, 3)+".\n\n");
    ta.appendText("The null hypothesis (no relationship between education and income)\n");
    ta.appendText("can be rejected at .05 if the Chi-Square value is greater than 3.84.\n\n");
    ta.appendText("Press the 'Continue' button to view a histogram of this statistic.");
  }
}
</pre></body></html>