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

  Calculate how many years since person was hired

Write a program with a class that has 5 names, 5 salaries. 5 hire dates. Calculate how many years since person was hired

  Write recursive function that takes as input number of rows

Write a recursive function that takes as input the number of rows, n, and outputs the total number of pins that would exist in a pyramid with n rows.

  Prove the following property of boolean algebra

prove the following property of Boolean algebra . give a reason for each step !!

  Analyse systems integration requirements

H/615/1698-Systems Integration-Pearson BTEC Levels 4 and 5 Higher Nationals in Computing Specification-Analyse systems integration requirements.

  Explain the concept of scalability to the team

The project leader wants you to explain the concept of scalability to team. How would you do that? Several managers on the team have heard of TCO but are not quite sure what it is. How would you explain it to them.

  Implement a strategy that gives priority to actions

A states is partially explored if there exists an unexplored action. Implement a strategy that gives priority to actions that lead to interesting states.

  What do you consider to be major risks to your environment

What do you consider to be the major risks to your environment and why? Describe the risks and vulnerabilities involved in the above stated environment.

  Write a program that prompts a user repeatedly

Write a program that prompts a user repeatedly to enter a number. When the user enters 0, the program should print the total.

  Write a program that reads in two sparse matrices and stores

We are assuming that the matrices are too large to fit into memory as arrays, thus all calculations must be carried out with the matrices stored in their linked list format.

  What is the wireless technology that uses directional earth

COMPUTER 501 University of Phoenix what is the wireless technology that uses directional earth station dishes? can this technology be used to wirelessly

  What is the minimum size in bits of the frame

What is the minimum size in bits of the frame buffer to store a frame? b. How long would it take, at a minimum, for the frame to be sent over a 10.5 MB/s

  Discuss how you would create and work

Discuss how you would create and work with a macro at your place of employment or at your home and Discuss how you could use Power Tools at work or home

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