Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the 'MyGreatExceptions.java` file // You must modify this file so that it works as described import java.util.Scanner; import java.io.*; public class MyGreatExceptions { }

image text in transcribedimage text in transcribed

the 'MyGreatExceptions.java` file // You must modify this file so that it works as described import java.util.Scanner; import java.io.*; public class MyGreatExceptions { } public static void main(String[] args) { Scanner inScan, fScan = null; int [] A new int [5]; inScan = new Scanner (System.in); System.out.println("Please enter the file to read from: "); String Name = inScan.nextLine(); Scan = new Scanner (new File (fName)); wwwwwww String nextItem; int nextInt = 0; int i = 0; while (fScan.hasNextLine()) { } nextItem = fScan.nextLine(); wwwwwwwwwwww } nextInt = Integer.parseInt (nextItem); wwwwwwww wwwwww A[i] = nextInt; i++; System.out.println("Here are your + i + "items:"); for (int j = 0; j < 1) { System.out.println (A[j] + There are three types of exceptions this file needs to handle in order to run correctly. The exact exception names are below along with how they may occur within the program. The input file you will be working with is called pretend you have this file. `exceptionsdata.txt`. **Note: ** You are not permitted to change any of the lines of code inside this file. However, the code in here might need to be wrapped inside other loops or more try/catch blocks. You are not permitted to create any of methods to help you, you may create a 'resize method for the array but that is all. This is not required as you could do all the resizing code within the main method, but you are allowed to create a method to do this as that is what we saw in the class example. You are not allowed to call any extra pre-built Java methods. to help you complete any of the requirements. #### IOException This exception could occur if the file name or file path to be reading from is incorrect. - Our program should continually ask the user for a file name until a correct one is provided - the correct file name that needs to be entered is `exceptionsdata.txt` #### NumberFormatException Once we have the correct file name we can read in the numbers. However, some text in the file will not be a number. Therefore, this exception could occur if the number on a given line is not a valid integer. - Do not add an invalid integers to the array Print out a simple message indicating a non-valid integer was found 3#### ArrayIndexOutOfBoundsException If we try to read in and store more than 5 values from the file - We must resize the array when this occurs double the previous size - We then copy the data into the new array and add the new item - We should print out a message that indicates resizing has occurred You can see what output should be [here] (/sample- outputs/exceptions output.txt). Important part of this file is the bottom half which is printing out the values in the array. Make sure all the numbers are in your print out when running Exceptionsoutput: www Please enter the file to read from: bogus Your file is invalid please re-enter Please enter Your file is invalid the file to read from: weasel please re-enter Please enter the file to read from: lablldata.txt bogus is not an integer weasel is not an integer Resizing array from 5 to 10 -- 300 150 400 -- Here are your 13 items: 100 200 600 250 800 50 500 450 600 550 -- 3.5 is not an integer -- ignored Resizing array from 10 to 20 -- ignored ignored

Step by Step Solution

3.32 Rating (146 Votes )

There are 3 Steps involved in it

Step: 1

Heres the modified MyGreatExceptionsjava file with the necessary modifi... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Accounting

Authors: Joe Hoyle, Thomas Schaefer, Timothy Doupnik

10th edition

0-07-794127-6, 978-0-07-79412, 978-0077431808

More Books

Students also viewed these Programming questions