SmartExpert

(118)

$30/per page/Negotiable

About SmartExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Business & Finance See all
Accounting,Business & Finance,Economics,English,HR Management,Math Hide all
Teaching Since: Apr 2017
Last Sign in: 3 Weeks Ago, 6 Days Ago
Questions Answered: 7559
Tutorials Posted: 7341

Education

  • BS,MBA, PHD
    Adelphi University/Devry
    Apr-2000 - Mar-2005

Experience

  • HOD ,Professor
    Adelphi University
    Sep-2007 - Apr-2017

Category > Computer Science Posted 25 Jul 2019 My Price 8.00

IT 111 Unit 4 Assignment

Assignment Details

Outcomes addressed in this activity: Unit outcomes:

  • Examine how functions get and return information about objects.
  • Use a decision structure in a program. 

Course outcome(s) practiced in this unit: 

IT111-3: Apply the programming constructs of iteration, assignment and decision-making. 

Instructions: 

Move to Closest Object 

NOTE: You can use any scene and any three objects in your own animation, and you can create any environment that you want. You may also use the environment and objects in the example if you prefer. 

Penguin Moves to Closest Object 

Our goal is to use conditionals to have a penguin move to the object that is closest to it (you will be using the objects of your choice). 

  1. Open Alice3.
  2. Scene setup: Begin with a anytemplate of your choice. Add any three objects of your choice. This example uses BigBadWolf (bipeds), Hare (bipeds), and Penguin (flyer, penguin (1st one)). Give the objects that you choose any name that you want to provide. Move one of your objects further away from the center object than the other. 

 

  1. Have the penguin state that it will move to the closest object (either the wolf or the hare). 

 

  1. You want to program the penguin to move to the closest object so you need to know how far away each object is from the penguin. This can be done by using the getDistanceTo function for the penguin.
  2. Click on the penguin. Click on functions tab and you will see a getDistanceTo function and notice that it has a parameter of other. You will come back to this function later.
  3. You will set up a variable by clicking on the Variable at bottom of screen and dragging it up into code area and placing as first line of program. A screen will open and you should set the value type to Double and the name to distanceHarewith the initializer as 0.0 as follows:

Note: If your version is saying DecimalNumber instead of Double, click on Window menu, select Preferences, then Programming Language, and then JAVA. 

 

  1. You should then have the following statements in your myFirstMethod method: 

 

  1. You want to use this double variable called distanceHare to hold the value that is the distance from the penguin to the hare. In the above statement, it is set to 0.0. Now, you can click on the penguin (in the function tab) and choose getDistanceTo. 

 

  1. Drag this tile over to the 0.0 in your first statement and drop it on top of the 0.0. It will ask us for the parameter of distance to what?  You should click on hare

 

  1. Create another variable which is a Double to be called distanceWolf and it will start at 0.0. Then drag the function penguin.getDistanceTo over top of the 0.0 and set the “other” to be wolf. 

 

Save the file as ClosestObject

  1. Now, you should have the computer make a decision about which object to move to. Which one is closer? If the distance from penguin to the hare is less than the distance from the penguin to the wolf, then you know that the hare is closer to the penguin than the wolf.
  2. Drag up an if tile to begin the setup of the if statement. Choose true

 

  1. Click on the down arrow next to the first true and then choose Relational Decimal number, and then choose ??? < ??? then distanceHare and finally then choose distanceWolf

  1. Your if statement should look as follows: 

 

  1. The statements that you drop into the area above the else are all done only if the condition is true. In this case, the condition will be true if the penguin is closer to hare than the wolf. On the TRUE case, you want to have the penguin say that the hare is closer, turn to face the hare, and then move forward 2 meters to the hare. 

 

  1. You have not programmed the ELSE part of the if statement, but you would like to test what you have so far. Since you know that the IF statement only gets executed when the penguin is closer to hare, purposely move the wolf farther away and make sure that the penguin is close to the hare and then RUN the program. The penguin should declare that the hare is closer, turn to hare and move 2 meters forward (towards hare).
  2. The ELSE block of the if statement gets executed when the hare is NOT closer (so wolf must be closer). In that case, you want the penguin to say that the wolf is closer, turn to face the wolf, and then move forward 2 meters as follows: 

 

  1. Run the program adjusting the hare and wolf to make sure it works in all cases. 
  1. If you run this program after moving the wolf close to the penguin, you will see that it works but it needs “tweaked” so that the penguin moves all the way to the wolf or hare instead of 2 meters each time. You know the exact distance to the hare and the exact distance to the wolf so use it and adjust the 2.0 to be distanceHare in TRUE case and adjust the 2.0 to be distanceWolf in the ELSE case.
    This can be done by clicking on the down arrow next to the 2.0 in the move statement or by dragging the local variable called distanceHare to the 2.0 in the move statement. 

 

  1. Run the program. Now, the penguin does move all the way to the hare or the wolf depending upon which one you placed closer to it. However, it actually moves right into them. This is because the distance is measured from its center to hare’s center or wolf’s center. This is too far. You can subtract .5 meters off the distance so it looks better.
  2. Click on down arrow next to the distanceHare in the penguin move statement line. Choose Math. Choose distanceHare - ????  Choose .5 

 

  1. This means that the penguin will move FORWARD the distance to the hare – ½ meter which means it moves almost the entire distance to the hare but it will no longer move all the way inside the hare. 
  1. Adjust the appropriate line in the ELSE block so that your program looks as follows:

  1. Run the program and see how it works. Edit the scene to make sure that the program works when the hare is closer and works when the wolf is closer. You should always test out every possible condition when using if statements in a program. In this case, you should test out when the distance to hare is less than distance to the wolf AND you should also test out when it is not.
  2. Save your file as MovetoClosestObject.a3p. Submit to the appropriate Dropbox. 

Requirements

  1. Create an environment of your choice and add any three objects that you want to use.
  2. One of your objects should be the central object, and one of the other objects should be farther away from the central object than the other.
  3. Use a function to determine which object is closest to the central object.
  4. Based on this information, and using an if/else statement, move the central object to the closest object.

Answers

(118)
Status NEW Posted 25 Jul 2019 06:07 PM My Price 8.00

IT -----------111----------- Un-----------it -----------4 A-----------ssi-----------gnm-----------ent-----------

Attachments

1564080214-IT 111 Unit 4 Assignment closetobject.zip
Not Rated(0)