Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Should be written in java Method Name: wordsFromFile Parameter(s): a String that is the name of a file to read Return Type: an array of

image text in transcribedShould be written in java

Method Name: wordsFromFile Parameter(s): a String that is the name of a file to read Return Type: an array of String Method Purpose: This method reads in data from the file named in the parameter and returns the data in an array. There is a specific structure to the file. The file contains a line with the number of lines following. This number is the size of the array needed to hold the data. Then, each following line is read and placed in the created array. For example, if the file looks like 3 David is cool then this method should make an array of size 3 containing ("David", "is", "cool"). This array is returned. You do not need to worry about whether that first line is an int or not - you can assume will always be an int. Exceptions: This method should use the method throws notation from Lecture 7. This means any FileNotFoundException that happens in the method is sent to where the method was called, and a try-catch is needed there. Note: There is some trickiness when mixing things like reading an int with nextInt and reading lines with nextLine. When you read the int, it reads the number and stops at whitespace (the new line). When you next ask for a line, it will read the blank newline as a line and put that in the first spot of the array. Then it will read more lines and put them in the array. The outcome of this is that there is a blank line in the array, and too many lines to read

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students explore these related Databases questions

Question

4. What will the team agreement contain?

Answered: 3 weeks ago