-
Create a class
Iterating. In it, create a (static) functionprintAllthat takes any object that implements theCollectioninterface onStrings. 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
Iteratingclass, add a (static) functionuseALthat creates an ArrayList of strings and callsprintAllto output them.Create another function
useHSthat creates a HashSet of strings and callsprintAllto output them. -
Create a class
NiceInputthat 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.