Category Archives: Alice

Guess Animal’s Weight – Using a Loop

Write a program in which the use is asked to guess the weight of an animal.  Allow the user 5 guesses to figure the weight of the animal.

Finished Project :

 

  1. Use a while-command-alice loop to keep track of the number of guesses and and the world function
  2.   use a < b  to keep track of how many times the user guessed the weight.alessthanb-alice-world
  3. If they guess the correct number then

 

 

Alice 2 Proximity Functions

One of the hardest concepts for younger programmers to learn is what returning a value means, a concept which Alice represents by its notion of ‘functions’.  And, in Alice, a great approach is to require students to move an object based on the distance  and to use a function to return the value of that distance and store it in a variable.

Every object in Alice has a set of proximity functions:
alice-2-proximity-functions

 

However, distance to, which most students will probably be most tempted to use is rarely what you want to use–especially when you want to move an object relative to another object using the calculated distance.

Consider, the picture below. Let’s say we want to calculate the distance between the hammer and the moon’s surface. Well, if you used distance to  to calculate the distance and move the hammer down, you’ll see that the hammer actually falls down into the moon. That’ s because the distance is being calculated from the center of the hammer and the center of the whole planet!

Instead, use distance above!

alice-distance-above-use-case

In the picture below, if you want the astronaut to move to the spaceship based off of a distance, you should try the distance in front of

 

alice-astronaut-space-ship

Before you jump into text coding with middle school coders  , Alice is a powerful tool for teaching what “returning a value” means.

Rock Paper Scissors [Alice 2]

Rock, Paper Scissor Game

We are going to create a Rock, Paper, Scissors game using Alice loops and if/else ‘s

  1. 1.Add a “rock”, “paper” and “scissors” objects to screen and enlarge them all to approximately the same size:rock-paper-scissors
  2. Make a Boolean variable called gamePlaying  and set its initial value to true : gamePlayingBoolean

3.Add a while loop based on gamePlaying

while loop

4. Make a variable called cpuChoice.   cpuChoice  is a number This variable will represent what the computer randomly chooses (rock, paper or scissors)

5. Use the world function that generates a random number so that the random number is an integer between 1 and 3 , inclusive.

alice-world-genare-random

Store the return value of that random number generator into cpuChoice  at the beginning of the loop

alice-random-range-

6. Debugging has many meanings. Experienced developers build debugging and logging into the development of their programs from the start.

  • We are going to do that in Alice by “watching” the cpuChoice variable

7. Right click on cpuChoice  and select watch this variable

alice-watch-variable

8 .Now we have the computer randomly choosing either 1,2, or 3 and these numbers will represent rock, paper and scissors respectively

So, what do you think we should do next?

Lesson continued here

rps__1

 

 

Math Expressions in Alice

Alice Supports many types of Math Operations.

 

For instance, let’s say that we have the variable someNumber  and it has a value of 2

alice-math_1

What if we want to multiply 2  by  0.5 ?

 

  1. click on the down arrow next to “2” and select “math”

alice-math_2

2) select “2*”  which means “2 times ”

alice-math_2

3) Select “Other” for the second number “b”

alice-math_3B

4) The calculator appears so you can  choose 5

 

5)  Select “5”

alice-math-calculator

6) Viola: You know have a math expression that represents 2 * 5

alice-math-4

 

8) Now let’s make a variable called “divisor” and then divide this expression by that

alice-math-5

9) Select the down arrow

alice-math-6

10) select as shown:

alice-math-7

 

11) Viola :

alice-math-8

 

 

 

Alice 2 : Asking User for Input

The world object has many, many useful functions including a way to ask the user for information—say  a number, a name or something.

  1.  Click on world
  2.  click on functions
  3. scroll down ot the ask user functions (See Diagram 1 ) and read below for more
Diagram 1

Diagram 1

 

Animated Gif showing the whole process of asking user for a number and then saying that number (using what as a String)

 

what-as-a-number-optiimized

Alice Unit 3-4 Assignments

FIRST:  make sure you know:  how to use What as a String and perform Math expressions  . You will not be able to do this assignment until you understand both of the above lessons.

Assign 1) Area of Triangle

Reference packets : #11, #12

Create a world that has a character (person/penguin/whatever) that will ask the user for the height of a triangle and the base of a triangle, and  calculate its area

  1. 3  different variables  : height , base  and  area  of the triangle
  2.  ask the user for  a number  for the height of the triangle and store it into  height (How to ask user for a number)
  3.  ask the user for  a number  for the base  of the triangle and store it into  base(ask user for a number)
  4.   use area formula and Alice Math expressions to compute the area.  (Note: if you don’t know how to use Math, refer to packet 11 or read this post  )
  5. Read this article if you have not already. ( You cannot do step 6 until you have read it)
  6. Have your character say the area of the triangle  (remember  area  is a number. You must use what as a string to say it.

alice-area-triangle-take2


 

roman-translator-1-20

Assign 2) Roman Numeral Translator

Objective : to let the user type in a number between 1 and 10 and then have a character “translate” that into Roman Numerals ( I, II, III, IV, V, VI, VII, VIII, IX, X)

  • Ask the user for a number and store the return value into a variable called  numberToTranslate
  • use a series of “if/else tests to translate the number and say the appropriate Roman translation for each number between 1 and 10
  • Use “==” (link )  to test if two values are the same.screenshot61
  • if the user enters a number greater than 10 then  OR less than 1 , have your character say, use either a or b “Only enter numbers between 1 and 10”

either-or-roman-trans_1

Final result :

either-or-roman-trans_2

We are going to use the roman Numeral Translator file again, so it’s important that you don’t lose the file and give it a good name that you can easily recognize in the future.

Extra credit: Translate 1-20 (Note : You still need to display an error if they enter a number that is too big, which in this case would be >21)


Assign 3) MPG

mpg_v1_opt


 Create a world in which the

  •  Create 3 variables :  miles, gallons ,MPG   
    •  2 of the variables  store the return value of a function
      • The user is asked for the number of gallons  of fuel his or her car can hold. Use the return value of the ask user for a number function as shown below.screenshot21
      • Do the same thing for the the number of miles  that he or she can drive on a full tank. Use ask a user function to set the value of the miles variable.
  • a third variable called MPG .   This one will store the result of some math and will hold the car’s miles-per-gallon (MPG). Calculate the MPG with the following formulampg (2)

 

  • At the end , your character should say the value of the mpg  . (You must use what as a string )

Lastly,

  • use an if/else  as follows
    • if mpg is less  than 30, say “wow, what a gas guzzler”
    • else say “This car gets pretty good gas mileage”

Assign 4) MPG  Temp Converter with if/else

temp-conver_opt1

 

  • Create a variable called degreesFahrenheit   .
  • Store the return value of the ask user for a number function in  degreesFahrenheit  
  • Create a variable called  degreesCentigrade
  • Use the following formula to convert the degreesFahrenheit   to Centigrade using the following formula below:

     
  • use a character from thePeople collection to say the centigrade temperature.
  • Don’t forget that you can’t say numbers, you must use what as a string
  • use an if/else so that you say “Wow it’s cold” If the final temperature is less than 5 and “Whew it’s hot” if the temperature is greater than 30  (Centigrade)

 


Assignment 5) Circle’s Area and Circumference: Create a world with your choice of person from the Peoplecollection. When you play the world, it should

  • Ask the user for the radius of a circle. (This value should be stored in a variable ).
  • Use a circle shape to represent the circle.
  • The person should then say the area and the circumference of the circle.( Links for the circumference formula , area of a circle)
  • (For an extra point do the same thing with a “Sphere“. Ask the user for the radius and calculate the surface area and the volume.)  This should be done in the same file as the circle.

 

 

Rock Paper Scissors


Assignment 5-extra credit ). Look up the formulas for the volume and surface area of a cylinder . Ask the user for the height of the cylinder and the radius, which should be stored in variables. Then calculate the surface area and volume of the cylinder . See if there is a cylinder shape in the gallery to use as a visual aid. And have an object say the volume and surface areas.

Methods , Variables, Functions Alice 2 Projects

 

#1  Apollo 15 :

screenshot.235

 

During the Apollo 15 mission to the moon, astronaut David Scott performed an experiment to prove that Galileo was right when he said that any two objects dropped at the same time would land on the ground at the same time in the absence of air. Scott, standing on the surface of the moon, dropped a hammer and a feather and indeed both objects hit the ground simultaneously.(Again, you must use “do together”)

Create an Alice world that recreates the experiment. You will find classes for the astronaut, lunar Lander, and the moon’s surface in the Web gallery’s Space collection. You can find a class for the Hammer in the Objects collection. Substitute any object of your choice for the feather.

Note : for following 3 steps, see Example 1 below

  1. Create a variable called  dropDistance
  2. set the value of this variable to the returned value of a distance function to make the objects fall the distance to the ground. (If stuck, read this )
  3. Make the two objects fall down the value of the distance

Example 1 (help with steps 2-4)

Steps 2-4 are similar to what is happening in the following picture :

screenshot.7

 


#2 Space Ship Repair :

spaceship-repair-demo-2

Create a space world with an astronaut and two spaceships(from the Web gallery’s Space collection). One of the spaceships is stranded with engine trouble, and the astronaut has arrived in the other spaceship to perform a repair.

  • The astronaut should initially be positioned just outside one of the spaceships, about to perform a space walk to the other ship. When the world is played, the astronaut should initially be positioned just outside one of the spaceships, about to perform a space walk to the other ship.
  • create a variable called walkingDistance ( to hold the distance that the astronaut must walk)
  • set the value of walkingDistance  to the returned value of a a proximity function  . (If stuck, read this ).  Here are some tips on using proximity functions in Alice 2.0.
    • NOTE: It turns out that, in this case, the best proximity function to use is distance to .
  • When the world is played, the astronaut should float to the stranded spaceship, appear to work for a few moments, and then float back to the rescue ship.
  • The repaired ship should then fly away, off the screen.

#3 Drag Racing:

spaceship-repair

 

  • Use  at least 1 set of comments
  • Create a world with a road (from the City collection) and two cars (from the Vehiclescollection).
  • Resize the road as necessary to match the size of the cars. The cars should be lined up side by side at one end of the road, which is a drag strip.
  • When the world is played, the cars should simultaneously move to the other end of the road and stop(You must use “do together”).
  • Change the duration of the method call that you use to move one of the cars so it is faster than the others.
  • Position the camera so you can see the cars as they approach the end of the drag strip.
  • Put an object at the end of the race to signify the ‘finish line’ and use a proximity function to move the cars to the end.

drag-racing-2


#4  Open Ended Project

  • Two or more objects
  • Must tell some kind of story
  • use at least 1 variable
  • use at least 1 function

bolivar_open_proj_penguin_ball cwong_open_proj_tag

Final Alice Assignment

This is your “cumulative Assignment”

  • It must tell a story
  • Minimum of 5 objects

 

Programming Requirements

  • Some kind of interactive event (#27) . Something should happen when a mouse is pressed, key is pressed etc

 

10 points of the following

 

  • Loop    (2 points )
  • variable (1 point)
  •  function (1 point)
  • custom object (save to file etc)  2 points

Alice Unit 5

5.1: Exercise Competition:

excercise_competition_emo

Three girls Jenny, Kelly, and Barb are enrolled in an exercise class. One day after class the three decide to have a friendly competition to see how many sets of 10 repetitions of running in place each can do before getting tired. Barb decides to go first and gets tired at 10 repetitions. Kelly goes next and she gets tired at 20 repetitions. Jenny, who has been in the exercise class for the longest, goes next. She gets tired at 30 repetitions.

Create a world that suites the competition.

  • Note: Basically, you are just using a parameter to determine how many times the girl “runsInPlace”
  • Important: Each of the girls should be an instance of ExerciseGirl class that you created in chapter 5.

 

excercise compe


 

EACH Assignment below requires the use of a parameter in some way.  If you do not have a parameter, as described, you will lose a lot of credit.

 

Here is a helpful link on how to create and use parameters, in case you forget.

 


5.2 : Jumping Jacks

jumping-jacks-optimized

Add a jumpingJack method to the ExerciseGirl class. The method should make the object perform jumping jacks .

  • Important: this method should have a parameter for the number of repetitions to perform.

5.3 : Marcello The Magician:

 

Marcello the magician has finally mastered his disappearing act. To perform the act, he places several items on a table in front of him. He stands with his right arm extended over an item. He says the magic word “Alakazam, Alakazee” and the object disappears. He repeats this procedure for each object on the table. Create a world in which Marcello (an instance of the Magician class from the People Collection) demonstrates his new act . In the magician object

  • you should create two new class-level methods:
    • sayMagicWords
      • should cause Marcello to say the magic words.
    • makeDisappear
      • This method should have an object as its parameter
      • should cause Marcello to turn to face the object, say the magic words (by calling the sayMagicWords method) and then make the object disappear by setting its opacity to zero (note: for some reason the bunny object cannot be made to disappear this way!).
  • gigantaicize
    • This method should have an object as its parameter
    • the object should be made to 5 times its original size!
  • Want to get an “A+”: then create a transmute method tha
    • takes an object  parameter
    • Changes a locust to a boar (hide the one , make the other appear)
    • changes a bird to a locust