// compete.java // competition of two populations in exponential growth (with quadratic feedback) // adapted from a program in basic by H.T. Odum & E. Odum, 1994 import java.applet.*; import java.awt.*; public class compete extends Applet { Label prompt1, prompt2, prompt3, prompt4, prompt5, prompt6, prompt7; TextField input1, input2, input3, input4, input5, input6, input7; Button drawbutton; double Q1, Q2, K1, K2, K3, K4, E, Q1i, Q2i, D1, D2, t, ti, R; int a; public void init() { prompt1 = new Label("Initial Population Q1: "); input1 = new TextField("3", 4); add(prompt1); add(input1); prompt2 = new Label("Initial Population Q2: "); input2 = new TextField("3", 4); add(prompt2); add(input2); prompt3 = new Label("K1 Growth rate of Q1: "); input3 = new TextField("7", 4); add(prompt3); add(input3); prompt4 = new Label("K2 Growth rate of Q2: "); input4 = new TextField("8", 4); add(prompt4); add(input4); prompt5 = new Label("K3 Mortality rate of Q1: "); input5 = new TextField("5", 4); add(prompt5); add(input5); prompt6 = new Label("K4 Mortality rate of Q2: "); input6 = new TextField("5", 4); add(prompt6); add(input6); prompt7 = new Label("Quadratic feedback (1/0)?: "); input7 = new TextField("0", 4); add(prompt7); add(input7); drawbutton = new Button("Draw"); add(drawbutton); } public boolean action(Event e, Object o) { Q1 = (float)Integer.parseInt(input1.getText()); Q2 = (float)Integer.parseInt(input2.getText()); K1 = 0.01f*(float)Integer.parseInt(input3.getText()); K2 = 0.01f*(float)Integer.parseInt(input4.getText()); K3 = 0.01f*(float)Integer.parseInt(input5.getText()); K4 = 0.01f*(float)Integer.parseInt(input6.getText()); a = Integer.parseInt(input7.getText()); repaint(); return true; } public void paint(Graphics g) { g.drawRect(0,120,320,180); t=0; ti=0; E=1; while (t<320) { ti=t+1; R=E/(1+K1*Q1-K3*Q1); if (a == 0) D1=K1*E*Q1-K3*Q1; else if (a == 1) D1=K1*R*Q1*Q1-K3*Q1; D2=K2*E*Q2-K4*Q2; Q1i=Q1+D1; Q2i=Q2+D2; if (Q1i<=180) { g.setColor(Color.green); g.drawLine((int)t, (int)(300-Q1), (int)ti, (int)(300-Q1i));} if (Q2i<=180) { g.setColor(Color.blue); g.drawLine((int)t, (int)(300-Q2), (int)ti, (int)(300-Q2i));} t=ti;Q1=Q1i;Q2=Q2i;} } } // Manuel Basler & E. Ortega, October 17th 2000