Question: In java please you will be taking the . java file I have provided and will be implementing the three methods I have setup for

In java please
you will be taking the .java file I have provided and will be implementing the three methods I have setup for you. Part One: Method 1: public static String[] convertFileToArray(String fileName) This method should convert the contents of the file into an array of words. Example: Say the file contains the following content This is a file containing text, and &. It becomes {this, is, a, file, containing,text,, and, &.} Essentially just take every sequence separated by spaces and make it an element of an array. The length of the array is equal to the total number of words. (Id use the String split function) Method 2: public static int countString(String[] array, String word) This method should calculate the amount of a given word in an array. Example: Say you have an array containing the following content {This, string, contains, the, word, the} And I call it with the word The This would return 2 Method 3: public static int[] getPositions(String[] array, String word) This method will return an array that indicates all the positions of word in the array
this is the code given
public static String[] convertFileToArray(String fileName) throws FileNotFoundException{ return null; } public static int countString(String[] array, String word){ return 0; } public static int[] getPositions(String[] array, String word){ return null; } public static void main(String[] args) throws FileNotFoundException {//TEST 1 String[] file1= convertFileToArray("File1.txt"); int countTheFile1= countString(file1, "the"); int[] file1ThePositions = getPositions(file1, "the"); System.out.println(countTheFile1); for(int pos: file1ThePositions){ System.out.println(pos); }//TEST 2 int countForFile1= countString(file1, "for"); int[] file1ForPositions = getPositions(file1, "for"); System.out.println(countForFile1); for(int pos: file1ForPositions){ System.out.println(pos); }//TEST 3 String[] file2= convertFileToArray("File2.txt"); int countRoadsFile2= countString(file2, "roads"); int[] file2RoadsPositions = getPositions(file2, "roads"); System.out.println(countRoadsFile2); for(int pos: file2RoadsPositions){ System.out.println(pos); }//TEST 4 int countSheFile2= countString(file2, "she"); int[] file2ShePositions = getPositions(file1, "she"); System.out.println(countSheFile2); for(int pos: file2ShePositions){ System.out.println(pos); }/*EXPECTED RESULTS 61422263147 END OF TEST 13102146 END OF TEST 21026437289126143145162168174 END OF TEST 37337990113118133152 END OF TEST 4*/}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!