Answers for Practice Final D Part A. 1. b i temp a[0] a[1] a[2] a[3] Output: ---+----+----+----+----+----+ 42 12 39 49 0 39 39 49 42 12 49 39 2 42 49 39 12 42 2. a A BufferedReader need not get its data from a disk file. It can also get its data from an InputStreamReader. 3. b To qualify as an ActionListener, an object must (1) announce its intention to be an ActionListener with "implements ActionListener" (2) contain an actionPerformed method. Part B. 1. f g x RetVal y RetVal Output: -----+------++-----+------- 263 331 Call 1 || Call 1 -----+------++-----+------- 16 | 259 || 5 | 15 -----+------++-----+------- Call 2 || Call 2 -----+------++-----+------- 3 | 12 || 14 | 33 -----+------++-----+------- 2. public static void main(String[] args) throws IOException { String line, name; char gender; int age, count = 0; double salary, maxF = -1.0, minM = 9000000000.0; BufferedReader br = new BufferedReader( new FileReader("c:\\salaries.txt"); line = br.readLine(); while(line != null) { StringTokenizer st = new StringTokenizer(line, ","); name = st.nextToken().trim(); gender = st.nextToken().trim().charAt(0); salary = Double.parseDouble(st.nextToken().trim()); if(gender == 'F' && salary > maxF) maxF = salary; else if(gender == 'M' && salary < minM) minF = salary; line = br.readLine(); } System.out.println("Max salary for women is " + maxF + "."); System.out.println("Min salary for men is " + minM + "."); } 3. public class Applet extends Applet implements ActionListener { private TextField t; private Button b; private int count; private double sum; public void init() { t = new TextField(12); b = new Button("Submit"); count = 0; sum = 0.0; add(t); add(b); b.addActionListener(this); t.addActionListener(this); setSize(125, 100); } public void actionPerformed(ActionEvent e) { if (t.getText().equals("")) t.setText(String.valueOf(sum / count)); else { count++; sum += Double.parseDouble(t.getText()); } } }