75%(20)15 out of 20 people found this document helpful
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.startDeclarationsScreen screen1Button sumButtonButton diffButton18
Programming Logic and Design, 8eSolutions 12-Button prodButtonTextbox usersEntry1Textbox usersEntry2Label resultscreen1.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)stopsumNumbers()DeclarationsLabel resultnum sumstring answersum = usersEntry1.getText() + usersEntry2.getText()answer = "The sum of the numbers is ", sumresult.setText(answer)screen1.add(result) return diffNumbers()DeclarationsLabel resultnum diffstring answerdiff = usersEntry1.getText() - usersEntry2.getText()answer = "The difference between the numbers is ", diffresult.setText(answer)screen1.add(result) returnprodNumbers()DeclarationsLabel resultnum prodstring answerprod = usersEntry1.getText() * usersEntry2.getText()answer = "The product of the numbers is ", prodresult.setText(answer)screen1.add(result) returnFind the Bugs19
Programming Logic and Design, 8eSolutions 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 screenclass LabelDeclarationsprivate string textprivate num horizontalPositionprivate num verticalPositionpublic void setText(string message)// setText() method requires a parametertext = messagereturnpublic void setPosition(num x, num y)horizontalPosition = xverticalPosition = y// vertical position should be the second parameterreturn// setPosition() returns nothingendClassDebug 12-02// This program creates a screen with a button.