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!
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?
|