We have discussed the fundamentals of programming as consisting of data & actions (often on data) and organizing the actions via sequence, selection, repetition and modularization. This practice/learning activity will revisit those ideas in more detail focussing on selection to organize the actions in a program (or set of scripts). The learning activity is described after the Process Reminders below.
Keep the "pair programming" process in mind as you work. One person types and the other person watches and corrects, questions, etc. After a bit (at most 30 minutes) you change roles.
This activity is for you to learn, so it is not graded. The learning will be inferred in the PARR (Programming Activity and Reflection Report) document you (eventually) submit and in one of the in-term exams. Remember to add to your notes for the PARR.
If you have questions about the assignment send me an e-mail or drop by my office. If you have a question while working on the assignment do the same. Keep in mind that when you encounter something you can't figure out you can/should think, explore, seek answers on google, etc. but, do not spend more than 15-30 minutes trying to overcome a particular error or problem.
The syllabus noted a couple ways you might earn extra credit. I am adding another.
One is to share some aspect(s) of programming or Snap! you think others might not have experienced. You should annotate your program using the program notes (File icon | Program notes) and/or comments blocks (see p.68 of the Snap! Reference Manual. The annotation should describe or explain the learning/insight(s) you want to share.
To receive extra credit for such an annotated program on this activity you will also need to submit a copy of your algorithms. Either create a PDF of a document or include the text in your submission message.
The alternative method to work for extra credit is that the partnership could suggest additions to our how to do it page. You might suggest a revision to clarify (or finish) something that is there already or an entirely new topic. Please indicate how/why you think the would be helpful. Be sure you fully and clearly describe what you are talking about.
The third method to receive a bit of extra credit is to submit the "Create your own problems ..." that you created and solved. Include all three problems and a pseudo-code algorithm of each solution.
Submitting something for either kind of extra credit is as simple as sending an e-mail message. The message should:
The goal here is to create and use Boolean expressions to decide which actions will get executed. We are at the point where programs/scripts are getting slightly more complex. We will be use selection statements (if
and if...else...
blocks. But when developing our algorithms and programs we will need to consider:
I suggest you use the following script in the Stage to control the program action.
Then for each problem there will a matching script that gets executed by some sprite. The code for that would replace the "say" block in the following script and perhaps use a different number in the "when I receive __" block.
Get values from the user for hours and pay rate.
Make up your own definitions for four conditions—frigid, cool, good, and hot. Get a value from the user for temperature.
Make up your own definitions for three conditions—bad, okay, and good. Include values for temperature, wind, and precipitation. Get values from the user for each condition.
Determine whether the number entered by the user is even. An even number is divisible by 2 or equivalently an even number mod
2 will result in 0.
BMI (body mass index) is often used to assess a person's weight. A BMI value of 18.5-25 is considered "normal" with 25-30 considered overweight and any value of 30 considered obese. Based on weight (in pounds) and height (in inches) values entered by the user characterize condition as underweight, normal, overweight, or obese. The formula for calculating the BMI is
weight · 703 bmi = -------------- height2
The normal range for height of American males is 69.5 inches ± 3 inches and for American females 64 ± 2.5 inches. Using whichever test you wish, get input from the user for height and characterize the height.
Using the information from the above item, get input from the user for height and gender, then characterize the height.
Note: (I figured out a better way to do this I think.) You will probably want to use the similar to that at the right to accomplish this task. Your actions for this item would be placed beneath the hatted block shown.
Add to the above script the possibility of the mouse being clicked on the x-axis, y-axis, or in one of the quadrants. Report whichever case it is.
Have one sprite determine whether it is closer to a second sprite than to the mouse (when the mouse is clicked) and if closer to the mouse glide there. Otherwise the sprite should move in a random direction the same distance as it is from the mouse.
Using two sprites with six dice costumes and a button you create for clicking to roll the dice, create a little craps game. Craps is played with two basic phases—come-out and point and starts in the come-out phase. Results are based on the roll total and the state of the game as described below.
There are three possible results of a roll in the come out phase.
announce "natural, winner"; state remains as initial state of the come-out phase
announce "craps, loser"; state remains as initial state of the come-out phase
announce "point is __"; set the point value; state gets set to the point phase
There are three possible results of a roll in the point phase.
announce "seven out, loser"; set state to the initial state of the come-out phase
announce "point-value, winner"; set state to the initial state of the come-out phase
announce "same shooter"; state remains as initial state of the point phase
Your script for the craps game will need to set the initial values for all variables (probably when it receives the action message). After that, the roll button sprite would use a (fairly complicated) if structure to evaluate the current state, roll the dice, and update the current state appropriately.