Arrays Chapter 6 Worksheet

Document Sample
Arrays Chapter 6 Worksheet Powered By Docstoc
					Use pages 295 to 312 in the Java AP Computer Science textbook and/or the
PowerPoint for chapter 6 on the teacher website. Type the correct answers in the
fields. Save this to your X drive.

AP computer Science

Answer the following questions:

 1. An array is a list of        .

 2. Java arrays begin with indexes starting at              to    .

 3. Array indexes are          data type.

 4. The size of an array is          .

 5. The values in an array are called array         .

 6. An array itself is an        .

 7. Once an array is created its size is        .

 8. Arrays must be accessed in the bounds of                to    .

 9. An array is created that contains 10 elements. int []nums = a new int[10];
     If you try to access nums[11] the java interpreter error will be      .

       Initialize each element in the nums array with intergers 0 - 9

 10. To find the size of nums[] you would use           .

 11. Change the element at index 3 to 14.

 12. Can the size of nums array be changes after it is created?

 13. Why do you not use the ( ) around the word length when you find the size of an
     array?     .

 14. Use an initializer list to initialize an array called score that hold the following
     values: 98, 80, 85, 92, 75

 15. Arrays can be passed as a parameter to a method. When the array is passed a
           of the reference to the original array is passed.
 16. Each          in an array must be instantiated separately.

 17. It is a good idea to use a       loop when handling arrays because the positions
     are        .

 18. Open up CreateArrays from the S Drive.

            a. Change the computeGrade method in the UnderGrad and GradStudent
               class to be return a String rather be void.
            b. Compile and run the CreateArrays program.
            c. Now create 2 Unicorn objects (refer to the Unicorn Constructor)
            d. Create 2 Pegasus objects (refer to the constructor)
            e. Create a unicorn array that consist of the two unicorn objects you
               created. Make it print Unicorn at index location and info from
               constructor unicorn[i]

(Sample output)
Unicorn at index 0 weight: 75 hornLength is 12
Unicorn at index 1 weight: 85 hornLength is 19

            f. Do the same for the 2 Pegasus objects.

 19. Log in to codingbat with your username and password.

Complete the following codingbat problems.
firstLast6 // see example below

   Example of firstLast6

   Given an array of ints, return true if 6 appears as either the first or
   last element in the array. The array will be length 1 or more.

   firstLast6({1, 2, 6}) → true
   firstLast6({6, 1, 2, 3}) → true
   firstLast6({3, 2, 1}) → false

   public boolean firstLast6(int[] nums) {
    if(nums[0] == 6 || nums[nums.length-1] == 6)
    return true;
    return false;