Inlab 7: Arrays
Due: Friday 22 July at 6:00 pm
- Use arrays and loops to access arrays.
This is an individual assignment, though collaboration (not
solution sharing) is allowed.
- Create a project called Inlab7 and type this into a Driver.
- Create a class called ArrayLab.
- Make an instance variable for an integer array.
- The ArrayLab constructor will take an integer parameter that
will be the number of elements in the array. Create the array
inside your constructor. DO NOT save the int parameter as an
- Create a method called initialize that will assign
each element in your array a random integer between 0 and 10.
- Create a method called print that will print out the
contents of your array as shown in the output below.
- Create a method called printStats that will find and
then print the average, maximum, and minimum value in your
- Create a method called search that searches your array
(and prints the result) for an integer parameter passed to your
- This lab is not as hard as it may sound. Do the methods one at
a time, in the order I outlined them above. You are practically
doing the same thing with each method. You use a loop to access
each individual element of the array. What you do with the
element changes, but the basic framework to manipulate the array
is the same.
- For the print method, you may assume that the array has at
least one element in it.
- printStats should only have one for loop in it.
- search should be taking a parameter, you are not prompting the
user for a number.
- If your array contains "3", two times, the print statement in
the search method saying it was found should only be printed out
- Here is output for the Driver
provided (results will vary due to the randomness of
By Friday afternoon at 6:00 pm, submit the file ArrayLab.java
into the appropriate D2L dropbox folder. DO NOT SUBMIT
Grading - 10 points
- 2 points - The constructor, initialization, and printing are
all done correctly.
- 3 points - printStats is correct (average is a double).
- 3 points - search is correct without extra print statements.
- 2 points - Good programming principles are followed (minimal
unnecessary code, efficient solution,...).