102k views
5 votes
Write a program named TheHill.java that reads in "The Hill We Climb" poem by Amanda Gorman that I am providing for you. Use good OOP. You must have a FileDialog so I can choose the location of my file. Your program should create an Arraylist < String > that stores the poem line by line. Have it print out the number of lines in the poem. Next ask the user how many of the lines they want to process.

1 Answer

2 votes

Final answer:

To solve this problem, you can create a Java program named TheHill.java using Object Oriented Programming principles. The program should read the poem line by line and store each line in an ArrayList. You can then print the number of lines in the poem and process a specific number of lines chosen by the user.

Step-by-step explanation:

To solve this problem, you can create a Java program named TheHill.java that uses Object-Oriented Programming (OOP) principles. The program should include a FileDialog that allows the user to select the location of the poem file. After selecting the file, the program should read the poem line by line and store each line in an ArrayList<String>.

Once the poem is stored in the ArrayList, you can print the number of lines in the poem by using the size() method of the ArrayList. To process a specific number of lines chosen by the user, you can use a Scanner to get input from the user and then loop through the ArrayList to retrieve and process the desired number of lines.

User Dan Monego
by
8.4k points