JAVA In this PoD you will use an ArrayList to store different pet names (there are no...

70.2K

Verified Solution

Question

Programming

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]

Answer & Explanation Solved by verified expert
4.3 Ratings (811 Votes)
import javautilArrayListimport javautilScannerpublic class    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students