Question: I need help creating a program in Java. Here is the question: a. Create a standard exception class called ThirteenException. b. Write a program that

I need help creating a program in Java. Here is the question:

a. Create a "standard" exception class called ThirteenException.

b. Write a program that repeatedly prompts the user to enter a string. After each string is entered, the program outputs the length of the string, unless the length of the string is 13, in which case the ThirteenException is thrown with the message "Use thirteen letter words and stainless steel to protect yourself!" Your main method should simply throw the ThirteenException exception out to the run-time environment. A sample run of the program might be:

Input a string > Villanova University

That string has length of 20

Input a string > Triscadecaphobia

That string has length 16

Input a string < misprogrammed

At this point the program bombs and the system provides some information, including the "Use thirteen letter words and stainless steel to protect yourself!" message.

C. Create another program similar to the one you created for part b, except this time, within your code, include a try-catch clause so that you catch the exception when it is thrown. If it is thrown, then catch it, print its message, and end the program "normally".

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