import java.awt.*; import java.awt.event.*; import java.util.*; public class Bugged extends Panel implements ActionListener { private TextArea text = new TextArea(); private Button test = new Button("Test"); public Bugged() { setLayout(new BorderLayout()); add(BorderLayout.CENTER, text); Panel p = new Panel(); p.add(test); add(BorderLayout.SOUTH, p); test.addActionListener(this); } public int smallest(int i1, int i2, int i3, int i4) { // Should return the smallest of the four parameters // Fix the indentation and identify the bug(s) if ((i1 < i2) && (i1 < i3) && (i1 < i4)) return i1; else if ((i2 < i3) && (i3 < i4)) return i2; else if (i3 < i4) return i3; else return i4; } public int largest(int i1, int i2, int i3, int i4) { // Should return the largest of the four parameters // Fix the indentation and identify the bug(s) if (i1 > i2) if (i1 > i3) if (i1 > i4) return i1; else return i4; else if (i3 > i4) return i3; else return i4; else if ((i2 > i3) && (i3 > i4)) return i3; else if (i2 > i4) return i2; else return i4; } public void test(int n1, int n2, int n3, int n4) { int big = largest(n1, n2, n3, n4); int small = smallest(n1, n2, n3, n4); text.append("Data: " + n1 + " " + n2 + " " + n3 + " " + n4 + " Largest: " + big + " Smallest: " + small + "\n"); } public void randomTest() { int n1, n2, n3, n4; Random r = new Random(); n1 = Math.abs(r.nextInt()) % 90 + 10; n2 = Math.abs(r.nextInt()) % 90 + 10; n3 = Math.abs(r.nextInt()) % 90 + 10; n4 = Math.abs(r.nextInt()) % 90 + 10; test(n1, n2, n3, n4); } public void actionPerformed(ActionEvent e) { randomTest(); } public static void main(String args[]) { Bugged b = new Bugged(); Frame f = new Frame(); f.add(b); f.addWindowListener(new WindowCloser()); f.resize(400, 200); f.show(); } } class WindowCloser extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } }