1 / 74

Distributing (Fun + Learning): The Distributive Property

Distributing (Fun + Learning): The Distributive Property. By: Peggy Li Under the direction of Professor Susan Rodger Duke University, June 2011. Overview. This tutorial will help you make an Alice world that lets you practice the distributive property .

dagmar
Download Presentation

Distributing (Fun + Learning): The Distributive Property

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Distributing (Fun + Learning):The Distributive Property By: Peggy Li Under the direction of Professor Susan Rodger Duke University, June 2011

  2. Overview • This tutorial will help you make an Alice world that lets you practice the distributive property. • An expression in the form a(bx+c) will appear, where a, b, and c are nonzero integers. • A possible answer for the expanded form will also show up. The user clicks Y if he/she thinks it is right, and N if he/she thinks it is wrong. • Concept can be further developed to practice more advanced concepts like adding algebraic expressions or using fractions.

  3. Creating a new world • Open Alice and create a new world. • Select a template of your choice. (This tutorial uses Grass, but any other works too.) • Click Open to start building your world. • Remember to save your world somewhere you can find it later!

  4. Adding a person • Click the green Add Objects button. • In the Local Gallery, scroll to the right until you reach the People folder. Click on the folder. • Scroll to the right until the very end. • You can use hebuilder and shebuilder to create your own character.

  5. Why hebuilder/shebuilder Just a quick explanation! • You might have noticed there are lots of other cool people to choose from in the People folder! • We’re going to use the Character Builder because it comes with some built-in methods that will be helpful later on. • Once you’re comfortable working in Alice, you can use an existing character and create new methods for it.

  6. Customizing your person • Customize your person! You can choose: • Body: head, torso, and legs • Face: skin tone, eyes, and lips • Hair: length/style and color • Clothing: shirt, pants, and shoes • Give your character a name and enter your name in the Created By box. Now click OK! Note: The person in this tutorial is named Guide. This will come up in future slides.

  7. Rotating the arms • Your person’s arms will be spread out like in the picture. Let’s move them back down to his/her side. • Find the Object Tree on the left. • Click the + next to your person’s name, then click the + next to upperBody and Chest. • You should now see parts called rightUpperArm and leftUpperArm.

  8. Rotating the arms • Right-click on rightUpperArm in the Object Tree. • Now go to Methods, select roll, and right. Click on Other and type in 0.2. • Do the same for leftUpperArm, but this time roll it to the left, again by 0.2. • Your person’s arms should look like this:

  9. Adding 3D text objects • Click on Add Objects again and return to the Local Gallery. • Scroll all the way to the right until you reach Create 3D Text, and click that. • Enter “a(bx+c)= ” for the text. • If you want, you can change the font. The tutorial will use Arial bold. • Make another 3D Text that says “abx+ac”.

  10. Renaming and turning 3D text • In the Object Tree, right-click on the first 3D Text you made and rename it “expression”. • Rename the second one “answer”. • Right-click on expression in the Object Tree. Go to Methods >> turn to face >> camera. • Repeat Step 3 for answer. • Both objects should now be facing you.

  11. Repositioning objects • Locate the object control buttons. Use them as needed to move and resize the objects until they look roughly like this:

  12. Changing 3D text color • We can change the color of the expression and answer text objects. • To do this, click expression in the Object Tree and go to the Properties tab. • Click the arrow next to color and choose any color. This tutorial will use blue. • Do the same for answer. The tutorial will use magenta.

  13. Making answer buttons • Now let’s make two answer buttons: one Y (yes/correct) and one N (no/wrong). • Go to Local Gallery >> Shapes folder and add two squares to your world. • Rename them yesButton and noButton. • Turn both squares to face the camera by right-clicking and going to methods >> turn to face >> camera. • In their Properties tabs, change the yesButton color to green and the noButton color to red.

  14. Making answer buttons • Now create two new 3D text objects, one that says “Y” and the other that says “N”. You can choose a font; the tutorial uses Arial, bold. • Rename them Yes and No and them to face the camera. • Move and resize them so that each is directly in front of the corresponding square. • Under Properties, set the vehicle of Yes to yesButton and No to noButton. This “glues” the letter to the square.

  15. Positioning answer buttons • Move the answer buttons forward and/or down (resize if needed) so they look like this:

  16. Getting a random expression • Let’s make a new method that will give us a random expression in the form a(bx+c). • Click on world in the Object Tree, go to the methods tab, and click create new methodwith the name getExpressions. • Click create new variable and make a new variable with namea and type number. Set its value to 0 (select other and type in 0). • Make two identical variables called b and c.

  17. Setting random numbers • Now we’ll set random values for a, b, and c. • Drag a while into the method and select true. • From the variables list, drag a over true, select a ==, and set b to 0.

  18. Setting random numbers • Drag another a, this time into the while loop. Select set value, and choose any number (we will change this in a moment). • Go back to world in the object tree. Under the functions tab, find the random number (under the third section Random). • Drag random number into the method, over the value you set a equal to.

  19. Setting random integers • Click the more right next to random number and set the minimum to -10. • Repeat Step 1 to set the maximum to 11 and integerOnly to true. • When we get a random number, it can include the minimum, but goes up to not including the maximum. Here we want numbers from -10 to 10, so maximum = 11. • We want integerOnly so the numbers are easy to work with – not long decimals!

  20. Getting a random expression • Click the more arrow at the end of the line and set duration to 0 seconds. • Drag the entire while loop to the clipboard in the upper right, to “copy” the contents. • Drag the clipboard back into the method, under the while loop, to “paste” the contents. • Repeat Step 3. You should have a total of three while loops in the method right now.

  21. Getting a random expression • In the second while, change both instances of a to b. Then, in the third while, change both instances of a to c. • The while statements ensure that a, b, and c are all nonzero so we don’t get anything too easy like 0(0x+2). Remember that a, b, and care were all first set to 0, so the while loop makes sure a new number is generated until the variable is no longer equal to 0.

  22. Getting a random expression • Now create two new number variables and name them ab and ac. Set both values to 0. • Drag ab into the method (below third while), and select set value >> expression >> a. • Click the arrow by a and choose math >> a* >> expression >> b. This just means a x b. • Repeat Steps 2-3 for ac, but remember to choose c instead of b. • Set the duration for both ab and ac to 0.

  23. Getting a random expression • Go to world’s functions tab, and scroll down until you find absolute value of a in Math. • Drag absolute value into the method, over the entire a*b (not just a). Repeat for a*c. • This means that ab and ac are both positive. We do this for formatting reasons, as we will see shortly.

  24. Getting a random expression • Create five new variables, all type String and set to default value. Name them aString, bString, cString, abString, and acString. • Drag aString into the method and set its value to default string for now. • Under world’s functions, find and drag the what as a string over default string. Choose expressions >> a. • Repeat steps 2-3 for the other four variables. Make sure you use the matching number! • Set the duration for each line to 0.

  25. Casting integers to strings • Scroll to the bottom of world’s functions and find int a as a string. Drag this over a, b, c, ab, and ac in the five lines and reselect the right variable name in expression. • What this does is remove the decimal format that otherwise comes with making an integer a string, using just what as a string. In other words, when 4 becomes a string, it is now just 4 instead of 4.0. • You do need to keep what as a string in addition to int a as a string.

  26. Setting integers as strings This is how the last five lines should look now. Make any changes or corrections if needed.

  27. Formatting the expression • Create two new variables called expression and rightAnswer, both of type string and with value default string. • Drag an if/else into the method and select true. • Drag the variable c over true and choose c < , then go to other and type in 0. • Now drag expression into the Do Nothing under the if and click set value >> default string. • Set the duration to 0.

  28. Formatting the expression • This slide and the next will be a little tricky, so take it slowly and carefully. • Drag an aString over the default string. • From world’s functions, drag a joined with b over aString and type in ( over default string. • Now drag in another a joined with b, this time over just the left parenthesis (. • Select expressions >> bString.

  29. Formatting the expression • Drag another a joined with b over bString. Go to other again, this time typing in x. • Drag an a joined with b over x and select expressions >> cString. • Now drag one last a joined with b over cString, go to other, and type in ). • Drag the entire expression set value to line to the clipboard, then drag the clipboard into the Do Nothing under Else. • Change the x to x+.

  30. Formatting the expression This is how your if/else block should look now: Close-up view between set value to and duration:

  31. Formatting the expression What just happened?? Let’s take a look. • Remember earlier we used absolute value. The absolute value of any number is positive (or zero, but also remember we aren’t using 0). • Our expression is in the form a(bx+c), where a, b, and c are integers from -10 to 10. • We set integers a, b, and c to strings: aString, bString, and cString. • Using lots of joined with statements, we made a string for the expression a(bx+c) with the numbers substituted in.

  32. Formatting the expression Why the c < 0 and changing x to x+ though? • This is just for aesthetic reasons (how it looks). • Let’s say we have x-2. We want it to show up as x-2, not x+-2. In this case, c = -2. • So we made the if/else. If the last number is < 0 (has a negative sign), we won’t add a plus between x and the number, or it’d say x+-2. • But else (if c is positive), we want a plus sign after x. Otherwise, it’d just say x2!

  33. Setting up the answers • Let’s make an array of four possible answers. • Create a new variable and call it answers. Make it an array of type string. Add four items with the following values: • Item 0: abx+ac • Item 1: abx-ac • Item 2: -abx+ac • Item 3: -abx-ac

  34. Setting up the answers The current item values are just guidelines to remind us what the format of each item will be. In a moment, we’ll change them to answers with answer numbers, not just the letters a, b, and c. To get wrong answers, we change the sign (+ to - ) since that’s a common mistake. Later, you can change them to different wrong answers or add more wrong answers if you want.

  35. Setting up the answers • First drag answers to the bottom of the method. • Select set item <index> to <item> in world. getExpressions.answers. • Choose 0, then default string. • Go back to world’s functions and drag a joined with b over default string. • Select expressions >> abString >> other >> x+. • Drag another a joined with b over x+ and go to expressions >> acString.

  36. Setting up the answers • Drag the set <index> to <item> line to the clipboard and drag the clipboard back three times, so you have four duplicate lines. • In the second line, change the index from 0 to 1 and change x+ to x-. • In the third line, change the index from 0 to 2. Drag a joined with b over abString and select expressions >> abString. Change the first abString to a – sign.

  37. Setting up the answers • In the fourth line, change the index from 0 to 3 and the x+ to x-. Repeat Step 3 of the previous slide to add in a negative sign ( – ). • Set the duration of each of the four lines to 0.

  38. Setting up the answers • We have just created an array with four strings, each representing a different possible answer. • Now, we’re going to set rightAnswer equal to the item in the array that is the correct answer, when the distributive property is used to write out the expression. • Remember that earlier, we got the absolute value of a*b and a*c. Absolute value is always positive, but a*b and a*c can be either positive or negative.

  39. Setting up the answers • We start with a(bx+c) and expand it to (ab)x+ac. For example, 2(3x-1) = (2*3)x+2*(-1) = 6x-2. • ab and ac can be positive or negative, but |ab| and |ac| are both positive (where | | means absolute value). In the example above, ab = 6 is positive and ac = -2 is negative, but 6 and 2 are both positive. • Our answers array already contains all the possible combinations, so now we just assign rightAnswer to the right item in the array.

  40. Assigning the right answer • Drag an if/else into the method and select true. • Drag a over true and choose a > . Go to other and type in 0. • Now click the arrow next to a and select math >> a* >> expressions >> b. • Drag another if/else into the Do Nothing area right below the If. Select true. • Repeat steps 2 and 3 to change the true to say a*c > 0(remember to choose c, not b).

  41. Assigning the right answer Note: ab refers to |a*b|, and ac refers to |a*c|. The reason we use a*b and a*cinstead of the variables aband ac is because ab and ac are always positive. We want to see if the value of a*b or a*c is positive or negative. So far, you should have:

  42. Four answer scenarios Note: We use ab to refer to |a*b|. Scenario 1: a*b > 0 and a* c > 0 + ab and + ac + ab, + ac  abx+ac  index 0 in array Scenario 2: a*b > 0 and a* c < 0 + ab and – ac + ab, –ac  abx-ac  index 1 in array Scenario 3: a*b < 0 and a* c > 0 – ab and + ac –ab, + ac  -abx+ac  index 2 in array Scenario 4: a*b < 0 and a* c < 0 – ab and – ac –ab, –ac  –abx–ac  index 3 in array

  43. Assigning the right answer First, let’s see what the two possibilities are when a*b > 0 is true: Inside the outer if statement a*b > 0: Inside the inner if statement a*c > 0: Scenario 1 Inside the inner else statement, so a*c < 0: Scenario 2 Now let’s apply this to our code!

  44. Assigning the right answer • Drag the variable rightAnswer into the first Do Nothing below if a*c > 0. Select default string for now. • Drag the answers array on top of default string, select ith item from array and then 0. • Set the duration to 0. • Set the rightAnswer equal to the ith item from array >> 1 in the inner else statement. You can use the same method or use the clipboard, then change the 0 to 1.

  45. Assigning the right answer • Drag the entire if/else block underneath the outer if a*b > 0 statement to the clipboard. • Now drag the clipboard below the outer else block to make a copy. • Change the item 0 to item 2 and item 1 to item 3 from the array. • This is because now a*b < 0, so if a*c > 0, we have Scenario 3. But when a*c < 0 also, we use Scenario 4. See next slide for more information.

  46. Assigning the right answer Let’s see what the two possibilities are when a*b < 0 is true: Inside the outer else statement a*b < 0: Inside the inner if statement a*c > 0: Scenario 3 Inside the inner else statement, so a*c < 0: Scenario 4 Refer back 4 slides to see the 4 possible scenarios.

  47. Assigning the right answer Your nested if/else statements should look like this:

  48. Getting a random answer • Congratulations! We are now done setting up the answers array and rightAnswer. • We need to choose a random item from answers to display. Our options include: • Shuffling the array, and always using the first item in the randomized order • Choosing a random number i and then getting the ith item in the array – this can be done with or without shuffling

  49. Getting a random answer • The problem with both ways is that with four answers and only one right one, there’s only a 25% chance the right one comes up! This makes it easier for someone to “cheat” by guessing NO most of the time. • We’ll fix this problem by making it so that the right answer comes up 50% of the time, and a random wrong answer the other 50%.

  50. Getting a random answer • Go to world’s functions tab and create a new function called getAnswer. Choose string. • Create two new parameters. One will be a string called rightAnswer. The other is an array of strings called answerArray. • Now create a new variable of type number and with name random. Create another variable of type string called answer.

More Related