CS 202 Fall 2012: Assignment 6

Homework Assignment #6 : Due Wednesday 10/24 before 5pm

The purpose of this assignment is to become more comfortable with Lists. You'll show your understanding by stepping through List operations in Scratch, create your own Scratch project for processing data, and explore how to make your own Wordle using someone else's software.

Part A: Understanding Lists in Scratch (2 points)

The goal of Part A is to show that you understand how to use Lists in Scratch (in particular, the "add", "insert", "delete", and "replace item" blocks). Assume the eight different Scratch scripts shown below are each separate programs (i.e., only one script runs at a time). Each script manipulates a list named “Mystery List”. Your job is to “execute” the scripts in your head to repeat the exact same steps and operations that Scratch would. For each of the eight scripts, show the contents of “Mystery List” at the end of the script. Be careful of the tiny but important differences across scripts!

Part B: Halloween Histogram (6 points)

The purpose of this assignment is to give you experience with Lists in Scratch. You will complete a project we have started. To get the initial code, go to the Scratch website:

http://scratch.mit.edu/projects/dusseau/2839532

This code tracks the amount of candy that someone has collected trick or treating, produces a histogram of the different types of candy, and allows you to trade candy for nutritious apples.

In the initial code you are given, the “When Green Flag Click” script controls the execution of all the other scripts; it broadcasts messages to start each script and waits for each script to complete before displaying the new contents of the variables and/or lists. You should not modify this main script.

You should also never modify the List called "Bag of Candy". Your scripts must work for any values of the Bag of Cany list (i.e., do not assume that there are always 100 pieces of candy collected; do not assume that the types of candy that appear in that list are the only types of candy that can be collected). (Hint: If you want to input new values for an existing list, right-click on the list showing on the Stage; if you select "import" you can pick a file containing a list that you previously "export"ed using this same interface.)

You are welcome to change the background and the costume of the main Sprite to any theme you desire, but this is purely optional.

You are expected to complete the five scripts that each begin when it receives a particular message. A yellow comment briefly describes the input, output, and expected action of each script.

You may find that the scripts become progressively more difficult to implement. You will want to complete the scripts in the order shown because many of the scripts use as input the output of previous scripts. You are free to create any new variables which you think are necessary. None of the scripts require many Scratch blocks, but every little detail does matter!

If you can't figure out the Scratch code that you need to write, you wil probably find it useful to think through the algorithm that you would follow if you needed to do these operations by hand. The code should be very similar to the steps you would do!

  1. Say First Five Candies: This script takes as input the list Bag of Candy that should have already been created and initialized for you. Each item of the list is one of the pieces of candy collected while Trick or Treating. You should modify this script so that the pumpkin sprite "says" (in a loop) the first FIVE candies in the list. Be careful if the list has fewer than five items! After saying the five items, the sprite should say whether or not there appears to be more candies still in the bag. Hint: You will need to allocate a new variable to allow you to index into each location of the two lists. (Yes, this script should be straight-forward to implement!)

  2. Make Unique Candy List: This script takes as input just the Bag of Candy List. For its resulting output, it adds items to a new list Unique Candy such that each item in the Bag of Candy appears exactly once in the Unique Candy List. For example, if the Bag of Candy list contains four items of "apple", "gum", "gum", "corn", then the Unique Candy List should contain three items: "apple", "gum", and "corn". The order of items in the Unique Candy list does not matter. Hint: You are likely to want to check if the Unique Candy list already contains a particular item before adding that item again.

  3. Say Unique Candies: This script takes as input just the Unique Candy list. It simply says each of the items in that list one at a time; that is, it says each type of candy that has been collected exactly one time. (Yes, this is easy again!)

  4. Tally Candies: This script takes as input the Bag of Candy list and the Unique Candy list you set up in the Make Unique Candy List script. It should add counts to the list Candy Tally to show how many of each type of candy you have. The order of the elements in Tally Candies must match the order of elements in the Unique Candy List. For example, if the Bag of Candy contains "gum", "chocolate", "gum", "snickers", then Unique Candy will contain "gum", "chocolate", and "snickers" and Tally Candies must contain "2", "1", "1" (in that corresponding order). This type of tally information for different categories is often referred to as a histogram.

    Hint: You are likely to want to implement a nested loop in this script. Specifically, you will probably have an outer loop that examines each element of the Unique Candy list; within each iteration of the outer loop you will enter another (inner) loop that examines each element of the Bag of Candy list; this inner loop will count how many candies it finds in the Bag of Candy list that match the particular Unique Candy. You will need separate index variables for each of the two loops as well as a variable to record the current tally for the current candy. This script is more challenging!

  5. Candy Trade: This final script allows you to trade 5 pieces of one type of candy for one apple. The new input to this script is "Trade Candy"; the main script asks the user for the type of candy they would like to trade and places the result in the "Trade Candy" variable; the "Trade Candy" script uses the value in this variable as input.

    The role of the script is to take away 5 pieces of the Trade Candy and add 1 apple. To do this, the Tally Candies list should be updated appropriately. You should not modify the original Bag of Candy list. (Note that in some cases you may need to add Apples to Unique Candy if that category wasn't present before!) So that the main script knows whether or not the trade was successful, this script should set the variable "Trade Result" to SUCCESS if the trade succeeded; it should set the variable to FAILURE otherwise (e.g., if there are fewer than 5 pieces of the Trade Candy).

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!

To show that your Scratch program computes the correct histogram for the Bag of Candy we gave you, in addition to submitting your Scratch .sb file, you should also submit two files containing the Unique Candy and Candy Tally lists. To do this, right-click on those lists showing on the Stage; select "export" and name the files appropriately. Note that you should make sure your Scratch project works on other test cases in addition to the Bag of Candy list we gave you!

Part C: Create a Wordle (2 points)

Wordle is a toy for generating “word clouds” from text that you provide. The clouds give greater prominence to words that appear more frequently in the source text. Wordles are created by constructing a histogram of the word counts in the text, just as you constructed in your Scratch code when tallying candy.

The following is a word cloud I created using the text for a old Homework in CS 202.

From the picture, you can easily see which words are repeated the most frequently in the homework specification; some of the words are interesting, like "scratch", "random", "song" and "music", while others are not so interesting, like "use" and "different".

In this part of the homework, you are to find some text that means something to you or you that you would like to analyze further. For example, good choices might be text corresponding to favorite song lyrics, a short story, or an article of interest. Copy and paste that text into the textbox here and click the "Go" button. Feel free to modify the colors, the font, and the shape of the cloud to make a picture you find pleasing.

You should be able to save your wordle by selecting to Print it (and then saving it as PDF); otherwise, you'll need to take a screenshot.

In a very short write-up about your wordle, state where you found the text you used. Briefly discuss the high frequency words and why they are or are not a good summary of the ideas behind the text.

Turning in your Homework

You should turn in all parts of this assignment through your Learn@UW account.

Remember that for Part B, you will submit three files: your Scratch .sb file, a text file containing the Unique Candy list, and a text file containing the Candy Tally list.

Menu

Fall 2012
Time: 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

  • CS202 Home
  • TAs and Lab Hours
  • Lecture Schedule w/ Slides
  • Grading
  • Homeworks
  • Projects
  • Exams
  • Scratch Examples
  • Readings
  • Computing Resources
  • Outreach Opportunity
  • Interesting Links
  • Scratch
  • UW Computer Sciences Dept