Assignment 4: Donut Calculator
You are planning to serve donuts after Mass. How many donuts will you need? Make a Scratch project to calculate the number of donuts required: ask the person using your project how many people will attend and how many donuts the average person is expected to eat. The number of donuts needed is the product of these two numbers. Create a visual representation of the number of donuts required using the “pen / stamp” block to repeatedly stamp out images of donuts on screen, one for each donut needed.
If you are stuck with how to get started or need to review how to complete the assignment, there is a video explaining and demonstrating how to complete it. This video has been updated to Scratch 3.0.
Use the “Ask” block to get the user to tell you how many people are expected to eat donuts, and how many donuts an average person will eat
Calculate and inform the user of how many donuts they will need
Stamp a copy of a donut sprite, once for every donut needed, to provide a visual representation of the required donuts.
Start new rows of stamped donuts when needed. When starting a new row, re-position the stamp to the start of the new row: change Y by the amount needed to move up or down a row, and set X to the starting position where each row begins.
You will need at least two sprites: a character to ask questions and respond with answers, and a donut. The donut can be hand drawn in the Scratch costume editor. Decorate it with sprinkles, make an apple fritter, go crazy! You can also make this a pie calculator, a cake calculator, a party favor calculator, or whatever other item you choose. Let your creativity shine! Make the dialog in your project make sense for your project’s theme.
Everywhere it is possible for you to assign a name or label, it must be meaningful and describe its purpose. This includes the project name, variable names, sprite names, and broadcast messages.
It is easy and fun to enter numbers which result in thousands of donuts. While you do need to stamp the donut images out in neat rows so they do not overflow the X axis, you do not need to do anything special when the donut stamping overflows the whole screen’s vertical space on the Y axis of 360 pixels. Size your donuts so you can show at least 50 donuts in rows on the screen at once without running out of space on the Y axis.
Blocks you will need to use:
|Variables||Create a variable for every piece of information you need. You will need at least two variables: one for the number of people and one for the donuts per person. Variables must have descriptive names and should be created “for all sprites” when you create them.|
|Sensing / Ask||Collect information such as the number of people eating donuts and average donuts each person eats|
|Sensing / Answer||The answer to the question asked. “Answer” only has the answer to the most recently asked question, so if you need to keep track of more than one answer, you will need to store the answer in a separate variable: drop the blue “answer” block from Sensing into the orange “set variable to __” block.|
|Control: Broadcast and When I Receive||Once all information is stored in variables, Broadcast a message such as “make the donuts” to the donut sprite. The donut sprite should have a Control / When I Receive block to start running when it receives the broadcast message.|
|Operators / Join||Join variables or calculated values together with text to form a sentence. For example “You are going to need 64 donuts” where 64 is a value calculated by your program. This is an example of string concatenation or the joining of pieces of text or writing into a larger sentence or statement.|
|Pen / Stamp||Stamps a copy of the sprite. You need to add the Pen extensions, see below.|
|Pen / Erase All||Clear the screen of any previously stamped sprites. Do this at the start of your project to start with a clean screen. You need to add the Pen extensions, see below.|
|Motion||Change X and Y values of the donut between stamps. This moves it around prior to stamping. You can also reference the x and y position as variables to know when you are at the end of a row and need to move down and left to the start of a new row|
|Control / Repeat||To control how many times you need to stamp the donut sprite. This is an example of iteration, a repeating sequence of instructions.|
That’s a lot of blocks! Take your time and experiment with each one to get comfortable with how it works.
Where are the “Pen” blocks?!?
The Scratch team moved the Pen blocks into an extension you will need to add to your Scratch workspace. It is easy — just two clicks! Look for the blue “add extension” button in the lower left corner of the window:
Click it and you will be able to choose from a selection of extensions to add new capabilities to your project. There are some other interesting extensions in there — feel free to play around with them. For this project, you will need to add the Pen extension so you may use the “Pen / Erase All” and “Pen / Stamp” blocks:
Is this too easy? Are you some kind of Scratch Ninja? Here are some extra features for those who seek to exceed expectations:
Change the program to reflect new information: children have a different appetite for donuts than adults! Collect more information (number of children, number of adults, how many donuts each eats) to build a more complex calculator.
Make it so it stamps boxes of a dozen donuts, including a partially filled box at the end for any remainder. How about a baker’s dozen?
Want to blow the roof off this project? Assume apple fritters cost $2 and mini cake donuts cost $0.50, and adults and children have different preferences such as adults will eat one apple fritter and children will eat some number of mini cake donuts specified by the person using your program. Calculate and display the quantities and cost of each type of donut, as well as the total cost. Present the information in a way that shows how much is being spent on children vs. adults.