Zebra0.com

alice arraysAlice Programming

Alice Programming

Learn Alice in FREE step-by-step lessons.

Quiz on Arrays: Working with lists of objects

After doing all parts of the lesson you should be able to answer these questions.

Write down the answers first. Click the check to check your answer.

1. How do you create an array? answer

   Just like creating a variable, but check the box for array. Then you will give it multiple values.

2. What data types can be made into an array? answer

   All data types, including any of the classes.

3. An array is declared as String[] words=new String[] {"please", "thank you", "you're welcome"}; What is the value of words[1]? answer

   "thank you" Remember numbering starts with 0.

4. One array is declared as String[] people=new String[] {"Sam", "Dave", "Amy"};
Another array has the ages of the 3 people: Integer[] ages=new Integer[] {12,6,20};
Because there is a one to one correspondence between these two arrays they are called _____ arrays. answer

   parallel

5. An array is declared as String[] people=new String[] {"Sam", "Dave", "Amy"};
What is the value of people.getLength? answer

   3: The length of an array is the number of elements.

6. An array is declared as String[]days=new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; Which is the best description of this code:
for(Integer i=1; i<6; i++) {
bunny.say(days[i];
}
answer

   The bunny says "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"

7. What is the correct order of the steps to create an array:
select a class or type,
add items to the array
drag a variable tile to the code window
check array answer

   Answer: 1. drag a variable tile to the code window, 2. select a class or type and check array (do in any order), 3. add items to the array.

8. An array is declared as String[] affirm=new String[] {"Yes", "You bet", "OK","Right"};
Is this a valid command: this.witch.say(affirm); answer

   No, you have to use a subscript: this.witch.say(affirm[i]);

9. Which of the statements below is correct to declare an array of bipeds?
Biped[]actors=new Biped[] { "this.ogre", "this.witch", "this.alien" };
Biped[]actors=new Biped[] { "ogre", "witch","alien" };
Biped[]actors=new Biped[] { this.ogre, this.witch, this.alien }; answer

   The last one

10. What does this code do?
answer

   The camel says "Hello", the gopher says "What's up?", the elk says "Yo!" and the fox says "Hey!"

Please review the material for any questions you miss.