Question: Write a program named Lab 2 8 B that does the following. a . Create an array of 5 integers. b . Place the following

Write a program named Lab28B that does the following.
a. Create an array of 5 integers.
b. Place the following statements into a try block.
i. Ask the user to input a filename
ii. Set up the input file
iii. Using a while hasNext() loop read the values from the input file into the array
iv. Print the array values (on one line with spaces) and total them as you read them
in
v. Calculate the average after the loop and print it
c. Write the catch block to catch an ArrayIndexOutOfBoundsException. Inside it, print the
error message and stop the program.
d. Write a second catch block for an InputMismatchException. Print the error message
yourself and stop the program.
e. To test your program, run it 3 times with these requirements.
i. Enter Input28B.txt; this should result in the error message for
"ArrayOutOfBounds"
ii. Enter Input28B2.txt for the text file name; this should result in the error
message for "InputMismatch".
iii. Enter Input28B3.txt for the text file name; the program should run correctly.
Write a program named Lab 2 8 B that does the

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