740 likes | 841 Views
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 .
E N D
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. • 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.
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!
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.
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.
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.
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.
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:
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”.
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.
Repositioning objects • Locate the object control buttons. Use them as needed to move and resize the objects until they look roughly like this:
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.
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.
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.
Positioning answer buttons • Move the answer buttons forward and/or down (resize if needed) so they look like this:
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.
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.
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.
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!
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.
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.
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.
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.
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.
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.
Setting integers as strings This is how the last five lines should look now. Make any changes or corrections if needed.
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.
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.
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+.
Formatting the expression This is how your if/else block should look now: Close-up view between set value to and duration:
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.
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!
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
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.
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.
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.
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.
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.
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.
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).
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:
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
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!
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.
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.
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.
Assigning the right answer Your nested if/else statements should look like this:
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
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%.
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.