import java.awt.*; import java.awt.event.*; public class BookPick extends java.applet.Applet implements ActionListener { TextField mQuery, mAnswer; Button bYes, bNo; int myLocation; public void init() { mQuery = new TextField(70); mQuery.setText("Do you wish a mathematical approach?"); bYes = new Button("Yes"); bNo = new Button("No"); myLocation = 0; mAnswer = new TextField(70); bYes.addActionListener(this); bNo.addActionListener(this); add(mQuery); add(bYes); add(bNo); add(mAnswer); } public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); if (myLocation == 0) { if (cause == bYes) { myLocation = 1; mQuery.setText("A programming focus instead of theory?"); } if (cause == bNo) { myLocation = 2; mQuery.setText("Narrow focus instead of overview of CS?"); } } else if (myLocation == 1) { if (cause == bYes) { myLocation = 3; mAnswer.setText("I recommend 'Oh! Pascal' by D. Cooper."); } if (cause == bNo) { myLocation = 4; mAnswer.setText("'Algorithmics' by D. Harel is a fine book."); } } else if (myLocation == 2) { if (cause == bYes) { myLocation = 5; mAnswer.setText("Try 'Karel the Robot' by R. Pattis."); } if (cause == bNo) { myLocation = 6; mAnswer.setText("Enjoy A. Biermann's 'Great Ideas in CS'"); } } } }