import awb.*; import java.awt.*; import java.awt.event.*; public class SavingsArray2 extends java.applet.Applet implements ActionListener { double table [], deposit, value, max, sum; int ilook, firstempty, j; DoubleField depositF, valueF; IntField ilookF, firstemptyF; Button b1, b2, b3, b4; public void init() { depositF = new DoubleField(20); depositF.setLabel("Deposit"); ilookF = new IntField(20); ilookF.setLabel("i"); firstemptyF = new IntField(20); firstemptyF.setLabel("First empty"); valueF = new DoubleField(20); valueF.setLabel("Value"); b1 = new Button("Make deposit"); b1.addActionListener(this); b2 = new Button("Check entries"); b2.addActionListener(this); b3 = new Button("Sum deposits"); b3.addActionListener(this); b4 = new Button("Find max"); b4.addActionListener(this); add(ilookF); add(depositF); add(firstemptyF); add(valueF); add(b1); add(b2); add(b3); add(b4); table = new double[100]; firstempty = 0; ilook = 0; table[0] = 0; } public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); if (cause == b1) { table[firstempty] = depositF.getDouble(); firstempty = firstempty + 1; firstemptyF.setInt(firstempty); } if (cause == b2) { ilookF.setInt(ilook); depositF.setDouble(table[ilook]); if ( ilook < firstempty - 1) { ilook = ilook + 1; } else { ilook = 0; } } if (cause == b3) { sum = 0; j = 0; while (j < firstempty) { sum = sum + table[j]; j = j + 1; } valueF.setDouble(sum); } if (cause == b4) { max = table[0]; j = 1; while (j < firstempty) { if (table[j] > max) { max = table[j]; } j = j + 1; } valueF.setDouble(max); } } }