Question: Using java, solve the question below. With the code that has already been given: A file contains decimal numbers separated by certain characters. For example,

Using java, solve the question below.

Using java, solve the question below. With the code that has already

With the code that has already been given:

been given: A file contains decimal numbers separated by certain characters. For

A file contains decimal numbers separated by certain characters. For example, in the file shown below the numbers are separated by one of the following characters, comma, semicolon, or hyphen 1.2,2.3-4.5;5.0 1.2 2.2-2.8-6.4-5.0-1.6-2.0 1.2,2.3, 4.5, 5.0 1.5-1.5-1.5;1.5,1.5,1.5 We will write a program that will print the averages of the numbers in each row. You are given an incomplete java class called Averaging. You have to complete the main method and two other methods. getDoubleArray method: As you can see from the signature this method will take two String parameters, a line red from the file and splitter, a string that could be a regular expression (regex). It will return a double array. For example for the line 1.2, 2.3-4.5;5.0 and the splitter [,;-) the method should return the array that contains the numbers 1.2, 2.3, 4.5, and 5.0. average method: This method takes a reference to a double array and return the average of the numbers in the array. main method: We are creating Scanner objects for you and including codes to read the filename and the splitter from the user. You are to write a loop that will: (a) Read the file line by line (b) For each line, call the getDoubleArray method. (c) Call the average method to find array returned by getDoubleArray method. (d) Print the averages in the format given in sample runs. Use the given files to test the program. You have to view the file (use notepad) to find the string or the regex for splitting lines. Sample Run 1 (for file called nums2.txt): > run Averaging Please Enter File Name: nums2.but Please Enter string or regex that separates numbers: Line 1: 3.25 Line 2: 1.2 Line 3: 3.3333333333333335 Line 4: 3.25 Line 5: 1.5 * HRB4B8MB9%8B4%BBH&B%%B 11 import java.io.FileNotFoundException; 12 public class Averaging 13 { 14 public static void main(String[] args) throws FileNotFoundException 15 { 16 Scanner kbInput = new Scanner(System.in); 17 System.out.println("Please Enter File Name: "); 18 String fname = kbInput.nextLine(); 19 Scanner fileInput = new Scanner(new FileReader(fname)); 20 System.out.println("Please Enter string or regex that separates numbers: "); 21 String str = kbInput.nextLine(); 22 /* Write a loop that will: 23 * (a) Read the file line by line 24 * (b) For each line, call the getDoubleArray method. 25 * (c) Call the average method to find array returned by 26 getDoubleArray method. 27 * (d) Print the averages in the format given in sample runs. 28 */ 29 } 30 /* This method takes line and split it using the given | 31 * "splitter" string. After that it will parse the 32 * numeric strings in the array of strings, save 33 * them in a double array and returns it. 34 */ 35 public static double[] getDoubleArray(String line, String splitter) 36 { 37 //Write codes here 38 /* We return null value so that file will compile. 39 * Change this line accordingly. Tis is the only 40 * line in the method that you can change. */ 41 return null; 42 } 43 44 //This method returns the average of numbers in a double array 45 public static double average(double[] arr) 46 { 47 I/Write codes here 48 49 /* We return 0.0 so that file will compile. 50 Change this line accordingly. This is the only 51 * line in the method that you can change. */ 52 return 0.0; 53 } 54 } **

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 Databases Questions!