Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program where main reads in one word names from a file placing a reference to each new object into an ArrayList called names.

Write a program where main reads in one word names from a file placing a reference to each new object into an ArrayList called names. (Be sure to ask for the name of the input file interactively.) This is the text file and its contents: namesforreversal.txt

Jacob Michael Joshua Matthew Daniel Christopher Andrew Ethan Joseph William Anthony Emily Madison Emma Olivia Hannah Abigail Isabella Samantha Elizabeth Ashley Alexis Sarah Sophia Alyssa

Print out the list one element at a time to the screen. Then call a method reverseArrayList, passing it a reference to the ArrayList names. The method reverses the order of all the elements in names. The main method should then prints out names in reverse order to the screen as shown:

Finally, Ask the user to enter an index for the array and then print out that element. This should be implemented in a loop that exits if the number entered is greater than or equal to the size, or less than 0.

A sample output looks like this:

Please enter name of file to with names to reverse: namesforreversal.txt

Original List:

Jacob

Michael

Joshua

Matthew

Daniel

Christopher

Andrew

Ethan

Joseph

William

Anthony

Emily

Madison

Emma

Olivia

Hannah

Abigail

Isabella

Samantha

Elizabeth

Ashley

Alexis

Sarah

Sophia

Alyssa

Reversed List:

Alyssa

Sophia

Sarah

Alexis

Ashley

Elizabeth

Samantha

Isabella

Abigail

Hannah

Olivia

Emma

Madison

Emily

Anthony

William

Joseph

Ethan

Andrew

Christopher

Daniel

Matthew

Joshua

Michael

Jacob

Please enter the number of the index you want to find the value for.

Index must be between 0 and 24 inclusive, Enter a number outside of range to exit: 24

The name at index 24 is Jacob.

Please enter the number of the index you want to find the value for.

Index must be between 0 and 24 inclusive, Enter a number outside of range to exit: 0

The name at index 0 is Alyssa.

Please enter the number of the index you want to find the value for.

Index must be between 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

Please Calculate the Earnings before taxes and the NOPAT

Answered: 1 week ago