Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using java, and the given code below For this assignment, you will complete the given program that is designed for reading names from a file

image text in transcribed

using java, and the given code below

image text in transcribed

For this assignment, you will complete the given program that is designed for reading names from a file and storing them in an array. Each line in the file has one name. a Arrays have predetermined sizes. Since we do not know how many names are in the file before we read it, this is problematic. We will find better solutions for this later. In this program, if the number of names in the file is less than the array size, we will read and store all of them in the array. Otherwise, we stop reading the file when the array is full. A print method for arrays is given to you. Notice that the print method stops printing after all "stored strings are printed (or just before the first null value is reached). The heading of getNames method is given to you. You are to complete the method. Method Requirements: 1. The getNames method should work for any size array and work with any file regardless of the number of names in the file. 2. If the number of names in the file is less than or equal to the size of the array, the method should write all the name in the file to the array. 3. If the number of names in the file is greater than the size of the array, the method should fill the array with the names that appear at the top of the array in the same order). 4. The getNames method cannot take any input (such as the number of names in the file) from user. 5. The method can contain only one loop. Simply, loop will read names one at a time from the file and store in the array. The loop should terminate either when the array is full, or end of file is reached. import java.util.Scanner; import java.io.FileReader; import java.io.FileNotFoundException; public class Review1 { //The main method calls a method that throws FileNotFoundException //Therefore we have to declare it. public static void main(String[] args) throws FileNotFoundException { //creating a String array of size 7 String[] names = new String[7]; //call the getNames Method getNames ("list4.txt", names); print(names); } //print method public static void print(String() list) { //if a string is notstored in list[k], it contains null value I/We want to terminate the loop at first nul value. for(int k = 0; k

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

Step: 3

blur-text-image

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 And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

8. Describe the steps in the development planning process.

Answered: 1 week ago