Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help write this program using both arrays and ArrayLists: You will begin

ID: 3548061 • Letter: P

Question

Please help write this program using both arrays and ArrayLists:

You will begin by using JFileChooser to locate a .txt file for input.

Bonus Opportunity:  5 points extra credit if you can limit the files shown in the showOpenDialog to just .txtfiles.

Part 1: read the file in two passes, using String[]

In your first pass, you will have to open the file, read it once to count the lines, and then close it.

Use the line count to declare and instantiate a String[] array large enough to hold the entire file.

Re-open the file, and read it, line-by-line, putting each line as a string into the String array.

Then you are to display the array, either on the console, or (for 5 points extra credit), in a scrolling list box in a GUI.

But here is the catch ... the order in which the lines are to be displayed is this:

For example, the input file:

1:Mary had a little lamb.

2:Mary likes lamb.

3:Especially well done with a little mint jelly.

4:Donna prefers goose.

5:For their eggs, golden or not

6:Donna likes roast goose, too.

Should be displayed as:

1:Mary had a little lamb.

6:Donna likes roast goose, too.

2:Mary likes lamb.

5:For their eggs, golden or not

3:Especially well done with a little mint jelly.

4:Donna prefers goose.

Part 2: Read the file in one pass, into an ArrayList<String>

Use the syntax:

ArrayList<String> myList = new ArrayList<String>();

to declare an ArrayList of Strings.

You will be reading the same input file again, so you can use the same file name you got from the original JFileChooser.

Using ArrayList, you can manage the reading job in a single pass -- you don't need to read the file first to get a count.

Read the entire file into the ArrayList

Then you are to display the array, either on the console, or (for the same 5 points extra credit), in a scrolling list box in a GUI.

But here is the catch this time:  Even though you will display the lines in the same order as in the file, you will display each line backwards.  For example, if an input line contained:

Mary had a little lamb.

You will display this line as:

.bmal elttil a dah yraM

To do this, you will find the toCharArray() method of the String class very convenient.

The file name should be Week08.java.  Remember, the first line of each submitted program file should contain a comment with your name and the assignment identification in it.

Explanation / Answer

Please help write this program using both arrays and ArrayLists: You will begin