the 'MyGreatExceptions.java` file // You must modify this file so that it works as described import...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
Heres the modified MyGreatExceptionsjava file with the necessary modifi... View the full answer
Related Book For
Advanced Accounting
ISBN: 978-0077431808
10th edition
Authors: Joe Hoyle, Thomas Schaefer, Timothy Doupnik
Posted Date:
Students also viewed these programming questions
-
Create a concrete LinkedList class that extends the provided ALinkedList class. You will need to override the extract()method in your class. You can use your main() method for testing your method...
-
Rainbow manufactures wooden backyard playground equipment. Rainbow estimated $1,785,000 of manufacturing overhead and $2,100,000 of direct labour cost for the year. After the year was over, the...
-
A 28.0-kg block is connected to an empty 2.00-kg bucket by a cord running over a frictionless pulley (Fig. 4-73). The coefficient of static friction between the table and the block is 0.45 and the...
-
Go to the Web site for The Wall Street Journal or some other financial publication such as Inc. magazine and identify a venture that has recently filed for reorganization or liquidation with the U.S....
-
Are the input specifiers for scanf() identical to the output specifiers for printf()?
-
Muggsy Bogues Company purchased equipment for $212,000 on October 1, 2014. It is estimated that the equipment will have a useful life of 8 years and a salvage value of $12,000. Estimated production...
-
Calculate the magnitude of the force on the charge q, given that the square is 10.0 cm on a side and q 9a9b = +7.46 C and qc = qa = -7.46 C. = 2.00 C, given that N
-
Manitoba Exporters Inc. (MEI) sells Inuit carvings to countries throughout the world. On December 1, Year 5, MEI sold 10,000 carvings to a wholesaler in a foreign country at a total cost of 600,000...
-
From my audit days it seemed that companies whether intentionally or not if they had inflating profits it was most common through the revenue recognition process Why do think this is the case
-
5. Consider the following algorithm. - ALGORITHM Enigma (A[0..n 1, 0..n-1]) //Input: A matrix A[0..n for i to n - 2 do - 1, 0..n1] of real numbers for ji+1 to n - 1 do if A[i, j] A[j, i] return false...
-
For Questions 11-15: Draw the Gantt Chart, individual waiting time and average waiting time (scrap paper) using the SHORTEST JOB FIRST ALGORITHM. Process P1 Arrival Time 0 CPU Time 5 P2 3 7 P3 5 2 P4...
-
Richard has an investment opportunity that'll pay 10%. He borrows half the funds at 4%. What will happen to his overall expected return?
-
Kerstin Dugmore plans to send their kids to college in 4 years and will need another $13,420.00 before they can do so. Given an interest rate of 1.00% compounded tri-annually, how much money do they...
-
1. What are 5 challenges with implementing ERP systems? 2. Discuss main different features between SAP and Netsuite? 3. Name 3 companies who have been using SAP successfully and what benefits has...
-
(a) Jacob commenced business on 1 January 2019 and acquired plant and machinery as follows: 1 April 2019 704,000 1 August 2019 388,000 Jacobs accounting policy is to charge a full years depreciation...
-
Use the method of Example 4.29 to compute the indicated power of the matrix. 1 0 1
-
On December 31, 2010, the city in question 2 makes its first annual lease payment. How does the city report the payment on government-wide financial statements? On fund-based financial statements?
-
Eximco Corporation (based in Champaign, Illinois) has a number of transactions with companies in the country of Mongagua, where the currency is the mong. On November 30, 2011, Eximco sold equipment...
-
Steve Reese is a well-known interior designer in Fort Worth, Texas. He wants to start his own business and convinces Rob ODonnell, a local merchant, to contribute the capital to form a partnership....
-
Discuss how a new brand manufacturer would go about defining their market segments and then begin to target them.
-
Go to www.kellogs.com, and examine the brands offered by Kelloggs. Using the BCG growth-share matrix, classify 10 brands as stars, question marks, cash cows, or dogs. Find at least one product you...
-
Diff Eyewear is a successful business built around a socially conscious mission. The company makes and sells stylish eyewear with comparable quality but a significantly lower price than luxury...
Study smarter with the SolutionInn App