Java

Exceptions Program

10 points

In this program, you'll practice working with some of the key concepts from Chapter 11 on exceptions. The Java file you'll want to download is: ExceptionsHomework.java. You can download it and create a NetBeans (or other IDE) project with it as the existing Java file.

You can also download: artists.txt, which is an input file.

The Java file has instructions on how to complete the program.

Once you have finished writing the program, run it. When the program asks for the input file, enter the path and name of the input file. for example: C:/Temp/artists.txt.

Here is output from a working program:

Once your program is working, test out your exception handling. Try committing these errors:

1. Misspell the name of the input file. (The program should respond: "File not found." And let you type in the name of the input file again.)

2. Try replacing the integer in the first line of the input file with a string. (The program should respond: "BadDataException: Expected integer in line 1 not found." And let you try again.)

3. Try replacing one of the ticket prices in the input file with a string. (The program should respond: "BadDataException: Expected integer for a ticket price not found." And let you try again.

4. When you're asked to enter a number for the artist you want to see, type in a string instead. (The program should respond: "InputMismatchException: An integer was expected." And let you try again.)

5. When you're asked how many tickets you want to purchase, type in a string instead. (The program should respond: "InputMismatchException: An integer was expected." And let you try again.)

If your program can handle these errors and not crash, you have good exception handling in your program.

 

Demo

Here is a zipped-up JAR file for the completed program. Right-click on the link to download the file to the root (H:, the top level) of your server space. Double-click the downloaded file to extract ExceptionsHomework.jar, artists.txt and EH.bat. Then run the program by double-clicking on EH.bat.