Question: In Java do the following tasks: Task 1: Define an exception class called MessageTooLongException. The class should have a default constructor. If an exception is

In Java do the following tasks: Task 1: Define an exception class called MessageTooLongException. The class should have a default constructor. If an exception is thrown using this zero-argument constructor, getMessage should return Message too Long!. This class should also define a constructor having a single parameter of type String. If an exception is thrown using this constructor, getMessage should return the value that was used as an argument to the constructor. Task 2: Write an application called UserInput that asks the user to enter a line of text having no more than 20 characters. If the user enters an acceptable number of characters, the program should display the message You entered x characters, which is an acceptable length (with the letter x replaced the actual number of characters). Otherwise, a MessageTooLongException should be thrown and caught. In either case, the program should repeatedly ask whether the user wants to enter another line or quit the program.

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!