Question: Write a Dog class (a dog has a name). Write a toString() method for this class. Create a Collection (how?) of dogs and put three

Write a Dog class (a dog has a name). Write a toString() method for this class. Create a Collection (how?) of dogs and put three dogs in it (Fido, Spot, Lucy). Print the whole Collection without using an explicit iterator, loop, or recursion. Using a for-each loop (not a standard for loop), traverse the Collection, and only print if the dog's name is Spot. Create an Iterator over the dogs. Write a for loop over your Iterator. Try each of the following, and comment each one out after you try it. Note the effects/exceptions in your comments. Inside the for loop, if the dog's name is Spot, add a new dog to the Collection inside the loop. Inside the for loop, if the dog's name is Spot, add a new dog to the Iterator inside the loop. Inside the for loop, if the dog's name is Spot, remove Spot from the Collection inside the loop. Inside the for loop, if the dog's name is Spot, remove Spot from the Iterator inside the loop. Think carefully: why do some things not work? Is that how you would implement the language
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
