-
Create a class
Iterating
. In it, create a (static) functionprintAll
that takes any object that implements theCollection
interface onString
s. So, its definition should look like this:public static void printAll(Collection<String> strings) { … }
The function should print out each string from the collection, one per line:
First string
Second string
last StringTo do this, you will probably need to use the for-each loop from Java 5.0 to iterate through the collection.
-
In the
Iterating
class, add a (static) functionuseAL
that creates an ArrayList of strings and callsprintAll
to output them.Create another function
useHS
that creates a HashSet of strings and callsprintAll
to output them. -
Create a class
NiceInput
that asks the user to enter a number, and stores it in anint
. The program should not crash if the user types something other than a number:Enter a number:
34
34 is a nice number.Enter a number:
two
That wasn't a number, but it was nice.You will have to catch an exception to do this. You should only catch the exception caused by incorrect input, not any other types.
-
Create a text file named
time.txt
. In it, indicate how long it took you to complete this lab exercise.
When you're done, create a ZIP file containing all of the files you created for this lab and submit it with the submission server.