Java TOPIC 48 – TEST REVIEW DETAILS & REVIEW
DETAILS
Minor
programming errors will not count against you. The test
covers most of the unit. Every year,
expectations vary a little bit depending on how much time we have. Your teacher will give you details. REVIEW QUESTION 1 – DEFINITIONS You should be
comfortable with the following terms:
QUESTION 2 – ARRAY VS
ARRAYLIST a)
What
is the difference between an array and an ArrayList? b)
Write
the statement to create an array that will hold 5 integers. Write the statement to create an ArrayList that will hold integers. c)
How
do we get the number of elements in an array?
How about in an ArrayList? d)
In
an array named arr, how do you set element 2 to the
value 7. In an ArrayList
named al, how do you set element 2 to the value 7. e)
In
an array, how do you output the value of element 5 to screen? In an ArrayList,
how do you output the value of element 5 to screen? QUESTION 3 – SHORT
ANSWER QUESTIONS Consider the
following array and answer the related questions: a)
What
is the array’s length? b)
What
is the index of the element with value 74? c)
What
is the value of element 3? d)
What
type of array is this? e)
Which
element contains the smallest value in the array? f)
What
is the maximum value in the array? g)
What
is the index of the minimum value in the array? QUESTION 4 – ARRAY
TRACING Trace the
array after each group of statements.
You can assume that all of these statements would be placed inside one
single program. So
any element unchanged in E would still have their value from D.
QUESTION 5 – CODING
QUESTIONS PART 1 b) Write the
for loop needed to output the array to screen one element at a time.
a) Write the
line of code required to create an integer array called coco of size 12. b) Write the
for loop necessary to initialize each element x in coco to x+1. So element 0
should get the value 1, element 1 should get the value 2, … c) Output the
array to screen by using the toString
function from the Arrays class. QUESTION 6 – ADVANCED
CODING QUESTIONS a)
Write
a function called same that will get two arrays as parameters and returns true
if the two arrays contain the exact same data. b)
Write
a function called maxValue that will get an
array as parameter and return its maximum value. c)
Write
a function called minIndex
that will get an array as parameter and return the index of the element
containing the minimum value. d)
Write
a function called indexOf
that will get an array and an integer v as parameters. It returns the index of the element that
contains the value v. If no element
contains the value v, then the function returns -1.
|
||||||||||||||||||||||||||||||||
Good luck!
There is always hope – at least a ray of
hope. J |
||||||||||||||||||||||||||||||||
|