Modify the HighArray class to implement the method specified below, which reads integer data from a...

60.1K

Verified Solution

Question

Programming

  1. Modify the HighArray class to implement the method specifiedbelow, which reads integer data from a file to fill the array. Thefirst integer read from the file should indicate the number ofintegers contained in the file which can be read into thearray.



/**
* Read integers into array from named file. First element in
* file is a count of number of integers contained in thefile.
*
* @param fileName   name of file containing integerdata
*/
void readIntFile(String fileName)

Note: Use the void insert(int value)method defined in the class to add each integer to the array as itis loaded from the file.

Here is a sample code to read datafrom file

import java.io.File;

importjava.io.FileNotFoundException;

import java.util.Scanner;

public class FileReaderSample {

    public static voidmain(String[] args) throws FileNotFoundException {

        Scanner in = newScanner(System.in);

       System.out.println(\"Please enter file name\");

      String s = in.nextLine();

       Scanner input = new Scanner(new File(s));

        int[] arr = newint[100];

        int i = 0;

        while(input.hasNextInt()) {

           int next = input.nextInt();

           arr[i] = next;

           i++;

        }// end while

        int nElems = i;

// Print the array contents

      System.out.println(\"Array Contents\");

        for (i = 0; i

           System.out.println(i + \"\t\" + arr[i]);

        }// end for

    }// end main

Answer & Explanation Solved by verified expert
3.6 Ratings (569 Votes)
Short SummaryImplemented the program as per requirementAttached source code and sample outputPlease do upvote to appreciate our timeThank youSource Codeimport javaioFileimport javaioFileNotFoundExceptionimport javautilScannerThis class reads integer data from a file to fill    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students