BUIS 305/INSS 505 SPRING 2020 Chapter 6 Individual Assignment
Due by 11:59PM on Wednesday June 24, 2020
Instructions: Complete the assignment based on your textbook reading, review of the Powerpoint slides, materials posted on Blackboard and research of the topic. In order to learn and retain the material, you are expected to respond using critical thinking and problem solving skills. Any instance of cheating, copying or other forms of plagiarism will result in a grade of zero for the assignment.
Review Questions, Programming Exercises
- What are the 3 ways to use constants with arrays?
As subscripts eg data[1]=0;
To define array size eg double[] prices=new double[3];
As array elements eg double[] prices={13.0,12.0,11.0};
- Describe linear search, binary search. Linear search involves traversing the whole array sequentially to find target value while binary search looks for the index of target value by comparing it to middle element in a sorted array.
- Define parallel arrays. These are arrays using multiple arrays to represent data on the same object.
Eg
int[] questions= {1,2};
boolean [] answer={true, false};
- What happens if a subscript is out of bounds? It generates error since it is outside the array.
- The first element in an array has a subscript of
- The last element in an array has a subscript of the size of array -1.
- At what point should you consider changing from individual variables to an array? When there is a large data set of the same data type. Isit reasonable to use an array when you only have two or three items to track? Yes, Why or why not? Consider the number of sets of those two or three items when making your decision. Arrays are dynamic thus easy manipulation
- Every element in an array always has the same data type. Why is this necessary?By definition, a declared array only holds data of the same type else generates an error.
- In the statement below, what value does the element at data[1]hold? 6
What value does the element at data[4] hold? 95.2
double[] data = {92.5, 98.6, 96.1, 90.0, 95.2};
- Write the Java code statement that creates an array of integers named data of size 5.
int[] data= new int[5];
- Write the Java code statementthat declares an array of integers called data with elements 7, -1, 13, 24 and 6. Use only one statement to initialize the array.
int[] data = new int[]{7,-1,13,24,6};
- Evaluate the following code fragment. What is the name of the array?a What is the size of the array? 7
Extra credit: What does the for loop do to the array? Add elements to the array. It also prints each array index and its element.
int[] a = new int[7];
for (int i = 0; i < 7; i++) {
a[i]= i + 1;
System.out.println(“Element at index ” + i +” is ” + a[i]);
}