JAVA
In this PoD you will use an ArrayList to store different petnames (there are no repeats in this list). This PoD can be done inyour demo program (where your main method is) – you don’t have tocreate a separate class for today.
Details
Create an arraylist of Strings, then using a Scanner object youwill first read in a number that will tell you how many pet names(one word) you will add to the arraylist.
Once you have added all the names, print the list.
Then read in one more pet name. If this is pet name alreadyexists, do nothing, but if the pet name isn’t in the list, add itto the front of the list (e.g., the first position).
Print the list again.
Next read in two more pet names. If the first pet name is in thelist, replace it with the second pet name. If the first pet nameisn’t in the list, add the second pet name to the end of thelist.
Print the list again.
Input
Example Input:
5 Whiskers Benji Lassie Smokey Bob Triffy Bob Max
Output
Example Output:
[Muffin, Benji, Snowball, Fluffy]
[Muffin, Benji, Snowball, Fluffy]
[Muffin, Benji, Snowball, Whiskers, Fluffy]