Use the exception class MessageTooLongException In a progra

@!@!

Use the exception class MessageTooLongException In a program 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 by 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. but instead name the class MessageTooLongException. Also, if an exception is thrown using the default constructor. getMessage should return \"Message Too Long!\" Define an exception class called CoreBreachException. The class should have a default constructor. If an exception is thrown using this zero-argument constructor. getMessage should return \"Core Breach! Evacuate Ship!\" The 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.

Solution

Import java .util.scanner;

Import java.util.*;

Import java .io.*;

Class meaasgelong extends message too long exception

{

Public static void main (string [] args)

{

Try

{

Char ch;

Do

{

Scanner keyboard=new scanner (system. in);

System.out.println (“enter the text :”);

String hr=keyboard.nextline ();

Int count=hr.length ();

If (count>=20)

Throw new message too long exception (0;

Else

{

System.out.println (‘you entered”+count+ “characteristics which is an acceptable length.”);

}

System .out.println (“do you want to continue? (Y/n”);

Buffered reader br=new new buffered reader (new input stream reader (system. in));

String s= br.readline ();

Ch=s.charat (0);

} while ((ch==’y’)// (ch==’y’));

} catch (messagetoolongexception ex)

{

System.out.println (ex.getmessage ());

}

Catch (ioexception ex)

{

System.out.println (ec.getmessage ());

}

}

}

Class message too long exception extends exception

{

Public message too long exception ()

{

Super (“message too long exception”);

}

Public message too long exception (string message)

{

Super (message);

}

}

@!@! Use the exception class MessageTooLongException In a program that asks the user to enter a line of text having no more than 20 characters. If the user ente
@!@! Use the exception class MessageTooLongException In a program that asks the user to enter a line of text having no more than 20 characters. If the user ente

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site