Starting from:
$35

$29

Lab 10: Exception Solution

Introduction

We have discussed exception handling in lecture (or recitation) as a method for reacting to and handling erroneous or unusual situations within program execution. In this lab, you will add some simple exception handling feature to a program in order to make it more robust in its execution

Download and read the le lab10.java. As given, the le will not compile due to an unhandled \checked" exception.

What to do

Your goal is to get the program to compile and to run in a fault tolerant way. Speci cally, you must handle the following exception:

An IOException could occur if the user enters an incorrect path or name  le the input  le. Your code should force the user to re-enter the  le name until a correct  le name is given.

A NumberFormatException could occur if the data on a given line is not a valid integer. Your code should ignore any invalid data value { do not put them into the array and do not increment the counter. Also print out a brief message indicating the error.

An ArrayIndexOutOfBoundsException could occur if more than 5 items are read in (since the original array size must be left at 5 as shown). In this case, you should resize the array to twice the previous size, copying the data into the larger array. Then add the new item to the array. Also, print out a brief message indicating the resizing has been done.

Be careful how you do these. Clearly, you must add one or more try catch blocks to the program.

You will also want to add a loop around the code to read in the    le.

Test your program on the input le lab10data.txt. It should produce output identical to that shown in lab10out.txt.

For help with this lab, see the course notes about exception as well as the corresponding handouts (ex23.java will be very useful). Chapter 11 in the text will also be helpful.

Grading

Demonstrate that your program works correctly to your TA by running it for him/her. For this lab, the following rubric will be used:

(4 points) IOException for  le and loop

(2 points) NumberFormatException for input data

(4 points) ArrayIndexOutOfBoundsException and resizing the array

Note that your program must work and your output must match that shown in lab10out.txt to receive credit for these items.







CS/COE 0401 | Intermediate Programming with Java    Page 1
Lab 10: Exception



Due Date and Submission

Once you completed the program, you must demonstrate your program for your Lab TA. Once your TA already checked you, DO NOT FORGET to submit your Lab08.java le to the CourseWeb under this lab by the due date.

If you do not complete the lab this week, you may nish it and submit your code to the CourseWeb before the due date. However, you need to demonstrate it to your TA at the beginning of next week’s lab.

No late submission will be accepted.






















































CS/COE 0401 | Intermediate Programming with Java    Page 2

More products