![Java: An Introduction To Problem Solving And Programming Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780134710754/9780134710754_largeCoverImage.gif)
Explanation of Solution
Creating “Main.java”:
- Create a class named “Main”.
- Define the “main ()” method.
- Declare required variables.
- Do till the user enters “n” using “while” condition.
- Get the string from the user.
- Check if the length of the string is greater than or equal to 20.
- Create an object “e” for the class. Here the exception is thrown using default constructor.
- Get and print the message using the method “e.getMessage()”.
- Else,
- Print the number of characters.
- Ask whether the user wants to continue or not and store the response in a variable “response”.
- Check if the response is equal to “n”.
- Break the loop.
- Define the “main ()” method.
Creating “MessageTooLongException.java”:
- Create a class named “MessageTooLongException” that extends “Exception”.
- Define a default constructor that calls the parent class’s method using “super ()” by passing a message.
- Define a parameterized constructor that calls the parent class’s method using “super ()” by passing a message that is given as the argument.
Program:
MessageTooLongException.java:
//Define a class
public class MessageTooLongException extends Exception
{
//Default constructor
public MessageTooLongException()
{
//Call the parent class by passing the message
super("Message Too Long!");
}
//Parameterized constructor
public MessageTooLongException(String message)
{
//Call the parent class by passing the message
super(message);
}
}
Main.java:
//import the package
import java.util.Scanner;
//Main class
class Main
{
//Define main method
public static void main(String[] args)
{
//Create an object for the scanner class
Scanner sc = new Scanner(System.in);
//Declare required variables
String str, response = "y";
//Do till the user enters 'n'
while(response...
![Check Mark](/static/check-mark.png)
Want to see the full answer?
Check out a sample textbook solution![Blurred answer](/static/blurred-answer.jpg)
Chapter 9 Solutions
Java: An Introduction To Problem Solving And Programming Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
- (Using R language)arrow_forwardAfter our initial deployment for our ML home based security system, the first steps we took to contribute further to the project, we conducted load testing, tested and optimize for low latency, and automated user onboarding. What should be next?arrow_forwardWhy investing in skills and technology is a critical factor in the financial management aspect of system projects.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)