Question: Help. Task 6 (20 pts.) File Sumintegers.java given below contains an incomplete program The goal of the program is read a file, identify all the

Help.

Help. Task 6 (20 pts.) File Sumintegers.java

Task 6 (20 pts.) File Sumintegers.java given below contains an incomplete program The goal of the program is read a file, identify all the lines that contain ONLY integers (no other text or spaces), and sum up all the integers that appear in those lines. Complete that program, by defining a sumIntegers function, that satisfies the following specs: Function sumIntegers takes one argument, called filename, that is a string. The function opens the text file specified by filename, identifies all the lines that contain ONLY integers (no other text or spaces), and returns the sum of all the integers that appear in those lines. If the file could not be opened, the function should return 0. IMPORTANT: You are NOT allowed to modify in any way the main function. You are free to define and use auxiliary functions. Hints: Remember that Integer.parseInteger can convert strings to integers. Also remember to properly handle possible exceptions that can be caused by such conversions This is an example run of the program, using input file siin1.txt Please enter the name of the input file: siinl.txt result 22. Note that the program returns the result of adding 12 and 10 in this example. Integer 2010 is ignored because of the presence of text in that line. Integer 5 is ignored because of the presence of spaces at the beginning of that line. Integers 100 and 534 are ignored because they are separated by a dot. Integers 200 and 300 are ignored because they are separated by space. Function Integer.parseInteger handles all those cases appropriately Sumintegers.java import java.io.File

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!