A file named MAINTENANCE12 01txt is included with your downloadable student

A file named maintenance12 01txt is included with

This preview shows page 18 - 21 out of 31 pages.

1.A file named MAINTENANCE12-01.txt is included with your downloadable student files. Assume that this program is a working program in your organization and that it needs modifications as described in the comments (lines that begin with two slashes) at the beginning of the file. Your job is to alter the program to meet the new specifications. // Modify the program to allow the user to click any // of three buttons. One displays the sum of the two numbers. // The others display the difference and product respectively. start Declarations Screen screen1 Button sumButton Button diffButton 18
Programming Logic and Design, 8e Solutions 12- Button prodButton Textbox usersEntry1 Textbox usersEntry2 Label result screen1.setSize(200, 200) sumButton.setText("Click to sum the numbers you have entered") sumButton.registerListener(sumNumbers()) diffButton.setText("Click to find the difference between the numbers you have entered") diffButton.registerListener(diffNumbers()) prodButton.setText("Click to multiply the numbers you have entered") prodButton.registerListener(prodNumbers()) screen1.add(usersEntry1) screen1.add(usersEntry2) screen1.add(sumButton) screen1.add(diffButton) screen1.add(prodButton) stop sumNumbers() Declarations Label result num sum string answer sum = usersEntry1.getText() + usersEntry2.getText() answer = "The sum of the numbers is ", sum result.setText(answer) screen1.add(result) return diffNumbers() Declarations Label result num diff string answer diff = usersEntry1.getText() - usersEntry2.getText() answer = "The difference between the numbers is ", diff result.setText(answer) screen1.add(result) return prodNumbers() Declarations Label result num prod string answer prod = usersEntry1.getText() * usersEntry2.getText() answer = "The product of the numbers is ", prod result.setText(answer) screen1.add(result) return Find the Bugs 19
Programming Logic and Design, 8e Solutions 12- 1. Your downloadable files for Chapter 12 include DEBUG12-01.txt, DEBUG12-02.txt, and DEBUG12-03.txt. Each file starts with some comments that describe the problem. Comments are lines that begin with two slashes (//). Following the comments, each file contains pseudocode that has one or more bugs you must find and correct. Answer : Debug 12-01 // This is a Label class // It defines a label that can appear on a GUI screen class Label Declarations private string text private num horizontalPosition private num verticalPosition public void setText(string message) // setText() method requires a parameter text = message return public void setPosition(num x, num y) horizontalPosition = x verticalPosition = y // vertical position should be the second parameter return // setPosition() returns nothing endClass Debug 12-02 // This program creates a screen with a button.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture