CS 202 Fall 2012
Homework Assignment #4 : Due Monday 5:00 pm October 1
This homework has three parts. In the first part, you'll create and implement a math drill game in Scratch. In the second and third parts, you'll show your understanding variables and concurrency in Scratch.Part A: Create a Math Drill Game (7 points)
The purpose of this project is to help you become more comfortable using Variables. This project will be more strictly specified than most projects in this course, and as a result will not be as creative or open-ended. We anticipate that you will want to carefully review the material we covered about Variables in Lecture.The basic idea of this project is to create a Scratch project that can be used for drilling math facts. The program will ask the user to type in answers to math problems that have been randomly generated. In more detail, the program will ask the user how many questions to ask, have multiple levels of difficulty, track the number of wrong answers given, let the user know the correct answer, and evaluate the user's performance at the end. The specification for this project is as follows:
- An interesting Sprite on an interesting background must ask the user a series of math facts; the questions can be about either multiplication or addition.
- The project must begin by asking the user how many questions the user would like to answer. The user must type in a number between 1 and 20 (inclusive); if the user types in something different, the program should say that the input isn't recognized and quit.
- The project must ask the user the specified number of math questions; the math questions can be either addition or multiplication (it is your choice). The operands must be randomly generated (i.e., different each time the program is run).
- Before asking any questions, the project must ask the the user if the questions should be all Easy, Medium, or Hard difficulty. At the easy level, all operands are a single digit (i.e., between 0 and 9); at medium, all operands are two digits (i.e., between 10 and 99); at hard, all operands are three digits (i.e., between 100 and 999). HINT: If you use Variables carefully, you will not need to construct different scripts for each of the cases!
- The program should let the user have exactly three tries to answer each question correctly; the program should give some feedback such as "Try Again." If the user does not get the question correct after three tries, the program should notify them of the correct answer and proceed to the next random question.
- The program should track the number of wrong answers the user gives over the all of the questions. This number should be displayed to the user at the end of the program and the user should be evaluated into one of four categories based on this score (e.g., if they give 50% of the answers wrong, give a poor evaluation; between 50-75% is another category; between 75-99]% is a third category; 100% could be a final category). The project should display one of four different pictures that evaluate them depending on the number of wrong answers they gave.
- Name your variables well so that someone else can understand their purpose.
- Project Notes. Every Scratch project has Project Notes associated with it. Project Notes can be written from the "File" pull-down menu in Scratch. What should you write in the notes? Describe all of the features and details of your game; basically, a shortened version of the Specification above that matches what you actually implemented. You should also describe any known bugs or problems. The project notes are your way of communicating with the TA who will be grading your project; use the notes so that they can understand what you have done (or have tried to do).
As always, programming assignments and projects in this class should be done on your own. You may ask other students in the class questions, but you may not share code with anyone in the class. You may not use existing code that you find elsewhere, including the Scratch website. You may look at the behavior of existing Scratch projects for inspiration, but you should develop all of your code as a completely new project and not modify, re-mix, or build from any one else's code.
The Instructor and the TA are very happy to give you suggestions on how to implement your ideas. We won't necessarily give the answer, but we will try to guide you to a reasonable implementation. If you have bugs in your code (i.e., it isn't behaving like you expect), we are happy to take a look and see if we can see the problem. But, again, don't wait until the last minute to do your project if you are hoping for any advice!
Part B: Understanding Variables in Scratch (1.5 points)
Variables are an important aspect of programming languages. A variable can be viewed as a container for a value and the value that a variable holds can change (or vary) as the program executes or runs. Variables allow a program to remember different values; variables enable a program to then act differently depending on the current value of a variable.
Given a script in Scratch, you can execute the instruction blocks in your head and predict exactly how Scratch will execute those same blocks. The following script takes as input the initial value for the variable a. The repeat_until loop always performs exactly 8 iterations. During each iteration of the repeat until loop, the script modifies the value of a depending on the old value of a and the current value of i.
Hint: The i mod 2 block divides the current value of i by 2 and returns the remainder. In other words, if i is even, it returns 0; if i is odd, it returns 1.
Imagine the program is run three different times, each time with a different input value for a.
- a = 1
- a = 2
- a = 3
- The values of variables a and i at the end of each iteration of the repeat until loop. Given that the repeat until loop iterates 8 times, you will state the values of a and i at the end of each of those 8 iterations.
- What is the final value of a that is calculated?
Part C: Understanding Concurrency in Scratch (1.5 points)
Consider seven sets of scripts (A - G). Each set of scripts is a single program and is started when the Green Flag is clicked. Each set of scripts has a single variable: count.A
B
C
D
E
F
G
For each set of scripts above, is the cat Sprite running these scripts guaranteed to meow exactly 5 times (or more precisely, play the meow recording 5 times)? (Hint: The answers for Group A and for Group B are both yes. Make sure you understand why before proceeding!) If the answer is no, state why not.
Turning in your Homework
You should turn in this assignment through your Learn@UW account.Menu
Fall 2012Time: TuTh 9:30-10:45
Room: 1325 CS
Lab: 1370 CS (1st floor)
Instructor:
Prof Andrea Arpaci-Dusseau
Office Hours
TuTh 10:45-12:00
Office:
7375 Computer Sciences
Email: dusseau "at" cs.wisc.edu
Teaching Assistant:
Benjamin Bramble
Lab Hours (CS 1370)
Wed 2:00-4:00
Teaching Assistant:
Sharad Punuganti
Lab Hours (CS 1370)
Thu 1:30-3:30