Write a program that allows the user to type in a number

Assignment Help Computer Engineering
Reference no: EM133695104

Question: Write a program that allows the user to type in a number on the keyboard. When the user clicks the mouse, the program will calculate and display the square of the number that was typed in (e.g. if the user types in the number 12, then when the mouse is clicked, your program will display the value 144, i.e. 122). Your program should use Model-View-Controller design.

Here's the trick, though; Processing doesn't have any automatic way of letting the user type in a multi-digit number. It only detects each individual keypress as it happens. So we'll have to use a string variable to keep track of all the digits that have been typed in so far. When the mouse is clicked, we'll need to convert our string of digits into a number (an integer) and display the square of that number.

Your program should behave as follows:

When the program starts: The program simply displays a blank, black canvas.

When the user presses a key: Add any key that the user types to your string of digits. If the user presses a key that is not a digit, it's okay if your program crashes (adding error-checking is beyond the scope of this question). Always display the current digits that the user has typed in using the text() function.

When the user clicks the mouse: Convert the digits that have been typed in to an integer and display on the canvas the square of that integer. Then, make sure to reset the digit string variable to the empty string ("") so that the user can later type in a different number.

Figure 3: Canvas after typing the digits 42 and then again after clicking the mouse.

Hint 1: Assuming that digit_string contains digits typed in by the user, you can use the following line of code to convert the string data to integer data:

number = int(digit_string)

Hint 2: To use good Model-View-Controller design, both the digit string AND the current message will need to be separate variables in your model!

Reference no: EM133695104

Questions Cloud

Proposed mechanism of action of medication : What is the proposed mechanism of action of the medication(s). Why or why not might this be the most appropriate for the patient?
Are there major public health issues the cdc organization : Are there any major public health issues the CDC organization are currently focusing on 2024?
Do the entire survey in a single span of time : Do the entire survey in a single span of time, so that time of day, weather, usage, etc. will have as little impact as possible on your measurements
What is the best practices for operating mobile clinics : What is the best practices for operating mobile clinics, including staffing, equipment, and appointment scheduling.
Write a program that allows the user to type in a number : Write a program that allows the user to type in a number on the keyboard. When the user clicks the mouse, the program will calculate and display the square
Intervention for nutrition education workshops : Justification of Intervention for nutrition education workshops in combatting childhood obesity in the south Bronx
Explain how you identified the highest monthly return : Explain how you identified the highest monthly return and, more importantly, how did you test whether such a return was abnormal (show the model you used)
Determine the financial healthiness of the facility : Make recommendations based on your conclusions to move toward and maintain financial healthiness.
Do you agree with the doctors decisions : Do you agree with the doctors' decisions? Why or why not? Do you believe the guidelines were ethical?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd