Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.
Getting Ready: Before going any further, you should:
ColorFinder.java.
colors and names local variables or
attributes of ColorFinder objects?
colors?
colors[0]?
names?
colors?
Color objects have been instantiated?
Color objects?
Color objects to elements
of the array colors?
value)?
ColorFinder
class. In particular, make sure you understand how the colors
and names arrays are being used.
getColor() method in
the ColorFinder class. (Hint: Loop through the
names array until you find the appropriate index.)
Driver.
List interface.
ColorFinder.java
to ColorFinder.arrays.
ColorFinder.java
and open it.
colors and names
so that both are now List objects.
import something in order
to use the List interface. What line do you have
to add to the top of your class as a result?
colors and names
objects so that they are now ArrayList objects.
List objects
rather than arrays?
for loop that
store the names and colors. (Hint: Look at the documentation for
the ArrayList
class.)
ColorFinder class.
cannot find symbol ArrayList.
Why did you get this message?
getColor() method in
the ColorFinder class:
String key;
for (int i=0; i<names.size() && result==null; i++)
{
key = names.get(i);
if (description.equals(key))
{
result = colors.get(i);
}
}
for loop terminate?
ColorFinder class.
get() method calls.
ColorFinder class.
Map objects and some of the
benefits of hash maps.
ColorFinder.java
to ColorFinder.arraylists. (You may need this
class in the future. Don't lose it!)
colors and names
objects with the following:
private Map colors;
colors
and names objects.
colors object as a HashMap.
add() methods of the
names and colors objects in
the constructor of the ColorFinder class
with the following:
colors.put(key, value);
getColor() method in the
ColorFinder class so that it now uses the
HashMap named colors. (Hint: Look at
the documentation for the HashMap
class.)
ColorFinder class.
ColorFinder.java
to ColorFinder.hashmap. (You may need this
class in the future. Don't lose it!)
Copyright 2021