Skip to main content
Engineering LibreTexts

13.9: Special Topic- Are Computers Intelligent?

  • Page ID
    59286
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Contemporary computer interfaces are largely visual and graphical, and many things we use a computer for, such as word processing, still require us to type. Will there come a day when instead of typing a letter or e-mail message, we’ll be able to dictate it to our computer? Will computers eventually have the same kind of interface we have—that is, will we someday be able to carry on conversations with our computers? Clearly, a “conversational interface” would require substantial intelligence on the part of the computer. Do computers have any chance of acquiring such intelligence?
    The question of machine intelligence or artificial intelligence (AI) has been the subject of controversy since the very first computers were developed. In 1950, in an article in the journal Mind, Alan Turing proposed the following test to settle the question of whether computers could be intelligent. Suppose you put a person and a computer in another room, and you let a human interrogate both with any kind of question whatsoever. The interrogator could ask them to parse a Shakespearian sonnet, or solve an arithmetic problem, or tell a joke. The computer’s task would be to try to fool the interrogator into thinking that it was the human. And the (hidden) human’s task would be to try to help the interrogator see that he or she was the human.
    Turing argued that someday computers would be able to play this game so well that interrogators would have no better than a 50/50 chance of telling which was which. When that day came, he argued, we would have to conclude that computers were intelligent.
    This so-called Turing test has been the subject of controversy ever since. Many of the founders of AI and many of its current practitioners believe that computation and human thinking are basically the same kind of process and that eventually computers will develop enough capability that we’ll have to call them intelligent. Skeptics argue that even if computers could mimic our intelligence, there’s no way they will be self-conscious and, therefore, they can never be truly intelligent. According to the skeptics, merely executing programs, no matter how clever the programs are, will never add up to intelligence.
    Computers have made some dramatic strides lately. In 1997, an IBM computer named Deep Blue beat world chess champion Gary Kasparov in a seven-game chess match. In 1998, a computer at Los Alamos National Laboratory proved a mathematical theorem that some of the best mathematicians were unable to prove for the past 40 years.
    However, despite these achievements, most observers would agree that computers are not yet capable of passing the Turing test. One area where computers fall short is in natural language understanding. Although computers are good at understanding Java and other computer languages, human languages are still too complex and require too much common sense knowledge for computers to understand them perfectly. Another area where computers still fall somewhat short is in speech recognition. However, an American company recently demonstrated a telephone that could translate between English and German (as well as some other languages) in real time. The device’s only limitation was that its discourse was limited to the travel domain. As computer processing speeds improve, this limitation is expected to be only temporary. Thus, we may be closer than we think to having our “conversational user interface.”
    Natural language understanding, speech recognition, learning, perception, chess playing, and problem solving are the kinds of problems addressed in AI, one of the major applied areas of computer science. Almost every major research group in AI has a Web site that describes its work. To find some of these, just do a search for “artificial intelligence” and then browse through the links that are returned.

    adapter class

    callback design

    content pane

    containment hierarchy

    controller

    event model

    inner class

    layout manager

    lightweight component

    listener

    model

    model-view-controller (MVC)

    peer model

    pluggable look and feel

    view

    widget hierarchy

    Java provides two sets of Graphical User Interface (GUI) components, the Abstract Windowing Toolkit (AWT), which was part of Java 1.0 and the Swing component set, the GUI part of the Java Foundation Classes (JFC), introduced in JDK 1.1.

    Unlike their AWT counterparts, Swing components are written entirely in Java. This allows programs written in Swing to have a platform-independent look and feel. There are three built-in look-and-feel packages in Swing: a Windows style, a Unix-like Motif style, and a purely Java Metal style.

    Swing components are based on the model-view-controller (MVC) architecture, in which the component is divided into three separate objects: how it looks (view), what state it’s in (model), and what it does (controller). The view and controller parts are sometimes combined into a single user interface class, which can be changed to create a customized look and feel.

    AWT components are based on the peer model, in which every AWT component has a peer in the native windowing system. This model is less efficient and more platform dependent than the MVC model.

    Java’s event model is based on event listeners. When a GUI component is created, it is registered with an appropriate event listener, which takes responsibility for handling the component’s events.

    A user interface combines four functions: guidance/information for the user, input, output, and control.

    Components in a GUI are organized into a containment hierarchy that is rooted at the top-level window. JPanels and other Containers can be used to organize the components into a hierarchy according to function or some other criterion.

    The top-level Swing classes—JApplet, JDialog, JFrame, and JWindow—use a content pane as their component container.

    A GUI should minimize the number of input devices the user needs to manipulate, as well as the complexity the user needs to deal with. Certain forms of redundancy—such as two independent but complete sets of controls—are desirable because they make the interface more flexible and more widely applicable.

    A layout manager is an object that manages the size and arrangement of the components in a container. The AWT and Swing provide a number of built-in layouts, including flow, border, grid, and box layouts.

    A radio button is a toggle button that belongs to a group in which only one button from the group may be selected at the same time. A checkbox is a toggle button that always displays its state.

    A well-designed interface should reduce the chance of user error and should make it as easy as possible to recover from errors when they do occur.

    How can a button still be considered a component under the MVC model? This is a good question. The JButton class acts as a wrapper class and hides the model-view-controller details (Fig. [fig-p528f1]). When you instantiate a JButton, you still get a single instance. Think of it this way: Your body consists of several systems that interact (internally) among themselves, but it’s still one body that other bodies interact with as a single object.

    A component can indeed be registered with more than one listener. For example, the ToggleButton that we defined in Chapter [chapter-io] has two listeners. The first is the button itself, which takes care of toggling the button’s label. The second is the frame in which the button is used, which takes care of handling whatever action the button is associated with.

    Some components can have two different kinds of listeners. For example, imagine a “sticky button” that works like this. When you click and release the button, it causes some action to take place, just like a normal button. When you click and hold the mouse button down, the button “sticks” to the cursor and you can then move it to a new location. This button would need listeners for ActionEvents, MouseEvents, and MouseMotionEvents.

    To round a double you could use the Math.round() method. For example, suppose the number you want to round is d. Then the expression Math.round(100 * d)/100.0 will round to two decimal places. Alternatively, you could use the java.text.NumberFormat class. Both of these approaches were covered in Chapter 5.

    Many cars today have cruise control as a alternative way to control the accelerator. Push buttons, usually located on the steering wheel, are used to speed up and slow down, so you can drive with your foot or your hand.

    As an alternative, a north-west-center border layout for the top-level window in the Converter might work. So might center-south-east and center-south-west. What makes these possible is the fact that the layout manager will use up space in any edge area that is not assigned a component.

    A flow layout would not be appropriate for the control panel because you would have little control of where the convert button would be placed relative to the keypad.

    Interface design disaster: My car uses the same kind of on/off switch for the headlights and the windshield wipers. One is a stem on the left side of the steering wheel, and the other is on a stem on the right side of the steering wheel. On more than one occasion, I’ve managed to turn off the headlights when I intended to turn on the wipers.

    Modify the addRecentCut() method so it limits the cuts stored in the vector to the last ten cuts. Solution: Check the size of the vector after inserting the cut. If it exceeds ten, remove the last element in the vector.

    private void addRecentCut(String cut) {
      recentCuts.insertElementAt(cut, 0);
      if (recentCuts.size() > 10) { // If more than 10 cuts
        recentCuts.removeElementAt(10);  // remove oldest cut
      }
      cutsMenu.removeAll();
      for (int k = 0; k < recentCuts.size(); k++) {
        JMenuItem item = 
          new JMenuItem((String) recentCuts.elementAt(k));
        cutsMenu.add(item);
        item.addActionListener(this);
      }
    } // addRecentCut()

    Modify the addRecentCut() method so that it doesn’t duplicate cuts stored in the vector. Solution: Use the indexOf() method to search for the cut in the vector. If it’s already there, don’t insert the cut.

    private void addRecentCut(String cut) {
      if (recentCuts.indexOf(cut) == -1) {// If not already cut
        recentCuts.insertElementAt(cut,0);
        if (recentCuts.size() > 10) { // If more than 10 cuts
            recentCuts.removeElementAt(10); // remove oldest
        }
        cutsMenu.removeAll();
        for (int k = 0; k < recentCuts.size(); k++) {
            JMenuItem item = 
              new JMenuItem((String) recentCuts.elementAt(k));
            cutsMenu.add(item);
            item.addActionListener(this);
        }
      } // if not already cut
    } // addRecentCut()

    Explain the difference between the following pairs of terms:

    A model and a view.

    A view and a controller.

    A lightweight and heavyweight component.

    A JButton and a Button.

    A layout manager and a container.

    A containment hierarchy and an inheritance hierarchy.

    A content pane and a JFrame.

    Fill in the blanks.

    =14pt

    A GUI component that is written entirely in Java is known as a


    component.

    The AWT is not platform independent because it uses the


    model to implement its GUI components.

    The visual elements of a GUI are arranged in a


     .

    A


    is an object that takes responsibility for arranging the components in a container.

    The default layout manager for a JPanel is


     .

    The default layout manager for a JApplet is


     .

    =11pt

    Describe in general terms what you would have to do to change the standard look and feel of a Swing JButton.

    Explain the differences between the model-view-controller design of a JButton and the design of an AWT Button. Why is MVC superior?

    Suppose you have a GUI that contains a and a JLabel. Each time the button is clicked, the GUI rearranges the letters in the label. Using Java’s event model as a basis, explain the sequence of events that happens in order for this action to take place.

    Draw a containment hierarchy for the most recent GUI version of the OneRowNim program.

    Create a GUI design, similar to the one shown in Figure [fig-acmegui], for a program that would be used to buy tickets online for a rock concert.

    Create a GUI design, similar to the one shown in Figure [fig-acmegui], for an online program that would be used to play musical recordings.

    Design and implement a GUI for the CDInterest program (Fig. 5.18). This program should let the user input the interest rate, principal, and period and should accumulate the value of the investment.

    Design and implement a GUI for the Temperature class (Fig. 5.5). One challenge of this design is to find a good way for the user to indicate whether a Fahrenheit or Celsius value is being input. This should also determine the order of the conversion: F to C or C to F.

    Design an interface for a 16-button integer calculator that supports addition, subtraction, multiplication, and division. Implement the interface so that the label of the button is displayed in the calculator’s display—that is, it doesn’t actually do the math.

    Challenge: Design and implement a Calculator class to go along with the interface you developed in the previous exercise. It should function the same way as a hand calculator except it only handles integers.

    Modify the Converter application so that it can convert in either direction: from miles to kilometers or from kilometers to miles. Use radio buttons in your design to let the user select one or the other alternative.

    Here’s a design problem for you. A biologist needs an interactive program that calculates the average of some field data represented as real numbers. Any real number could be a data value, so you can’t use a sentinel value, such as 9999, to indicate the end of the input. Design and implement a suitable interface for this problem.

    Challenge: A dialog box is a window associated with an application that appears only when needed. Dialog boxes have many uses. An error dialog is used to report an error message. A file dialog is used to help the user search for and open a file. Creating a basic error dialog is very simple in Swing. The JOptionPane class has class methods that can be used to create the kind of dialog shown in Figure [fig-errdialog]. Such a dialog box can be created with a single statement:

    JOptionPane.showMessageDialog(this, 
             "Sorry, your number is out of range.");

    Convert the Validate program (Fig. 6.12 from Chapter 6) to a GUI interface and use the JOptionPane dialog to report errors.

    Challenge: Design and implement a version of the game Memory. In this game you are given a two-dimensional grid of boxes that contains pairs of matching images or strings. The object is to find the matching pairs. When you click a box, its contents are revealed. You then click another box. If its contents match the first one, their contents are left visible. If not, the boxes are closed up again. The user should be able to play multiple games without getting the same arrangement every time.

    Challenge: Extend the SimpleTextEditor program by adding methods to handle the opening, closing and saving of text files.


    This page titled 13.9: Special Topic- Are Computers Intelligent? is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Ralph Morelli & Ralph Wade via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.