1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alex777 [14]
3 years ago
6

2. Use inheritance to create a hierarchy of Exception classes -- EndOfSentenceException, PunctuationException, and CommaExceptio

n. EndOfSentenceException is the parent class to PunctuationException, which is the parent class to CommaException. Test your classes in a Driver class with a main method that asks the user to input a sentence. If the sentence ends in anything except a period (.), exclamation point (!), or question mark (?), the program should throw a PunctuationException. If the sentence specifically ends in a comma, the program should throw a CommaException. Use a catch block to catch all EndOfSentenceExceptions, causing the program to print a message and terminate. If a general PunctuationException is caught, the program should print "The sentence does not end correctly." If a CommaException is caught, the program should print "You can't end a sentence in a comma." If there are no exceptions, the program should print "The sentence ends correctly." and terminate.
Computers and Technology
1 answer:
Lelechka [254]3 years ago
5 0

Answer:

See explaination

Explanation:

EndOfSentenceException.java

//Create a class EndOfSentenceException that

//extends the Exception class.

class EndOfSentenceException extends Exception

{

//Construtor.

EndOfSentenceException(String str)

{

System.out.println(str);

}

}

CommaException.java

//Create a class CommaException that extends the class

//EndOfSentenceException.

class CommaException extends EndOfSentenceException

{

//Define the constructor of CommaException.

public CommaException(String str)

{

super(str);

}

}

PunctuationException.java

//Create a class PunctuationException that extends the class

//EndOfSentenceException.

class PunctuationException extends EndOfSentenceException

{

//Constructor.

public PunctuationException(String str)

{

super(str);

}

}

Driver.java

//Include the header file.

import java.util.Scanner;

//Define the class Driver to check the sentence.

public class Driver {

//Define the function to check the sentence exceptions.

public String checkSentence(String str)

throws EndOfSentenceException

{

//Check the sentence ends with full stop,

//exclamation mark

//and question mark.

if(!(str.endsWith(".")) && !(str.endsWith("!"))

&& !(str.endsWith("?")))

{

//Check the sentence is ending with comma.

if(str.endsWith(","))

{

//Throw the CommaException.

throw new CommaException("You can't "

+ "end a sentence in a comma.");

}

//Otherwise.

else

{

//Throw PunctuationException.

throw new PunctuationException("The sentence "

+ "does not end correctly.");

}

}

//If the above conditions fails then

//return this message to the main function.

return "The sentence ends correctly.";

}

//Define the main function.

public static void main(String[] args)

{

//Create an object of Scanner

Scanner object = new Scanner(System.in);

//Prompt the user to enter the sentence.

System.out.println("Enter the sentence:");

String sentence=object.nextLine();

//Begin the try block.

try {

//Call the Driver's check function.

System.out.println(new

Driver().checkSentence(sentence));

}

//The catch block to catch the exception.

catch (EndOfSentenceException e)

{}

}

}

You might be interested in
What is the encryption cipher that was the precursor to des??
Elanso [62]
DES works by using the same key to encrypt and decrypt a message, so both the sender and the receiver must know and use the same private key. Once the go-to, symmetric-key algorithm for the encryption of electronic data, DES has been superseded by the more secure Advanced Encryption Standard (AES) algorithm.
8 0
3 years ago
You have installed a point-to-point connection using wireless bridges and Omni directional antennas between two buildings. The t
kozerog [31]

Answer and Explanation:

Omnidirectional antenna are those antennas which receives the signals from multiple directions equally.These are the antennas that cannot  get the signal from a particular direction thus gives the low throughput.

To get high throughput, directional antennas should be installed because they receive the signal from a particular direction only .Thus the signal received from these antenna work for a certain area.Example-Television antenna at homes are directional antennas names as Yagi-uda antennas.

3 0
3 years ago
What item on a business card is generally the most prominent?
AveGali [126]
The most prominent
Company name that's most important
3 0
3 years ago
Read 2 more answers
How did Bill Gates benefit from free enterprise? Need a paragraph please. Will give the branliest!!
olchik [2.2K]

Answer:

Bill Gates used his skills and brains to build a business. In conclusion, Bill Gates was very successful with his industry thanks to free enterprise. He, along with his employees and friends, created and almost perfected the software known as Microsoft. The free enterprise system provides the right to private enterprise, which allowed him to choose his own business and to run it without governmental influence. Because he could create his own business and design his own products, Gates was able to specialize in technology.

Explanation:

8 0
3 years ago
Cuando fue creada la aplicación Adobe Photoshop (creada, no lanzada)
Cloud [144]

Answer:

en el año 1991

Explanation:

:)

4 0
2 years ago
Other questions:
  • With respect to the general classes of computers, a ________ is the most expensive and most powerful kind of computer, which is
    7·1 answer
  • (1 consider the following function definition: int func(int x, double y, char u, string name { //function body } which of the fo
    7·1 answer
  • Name the functional arms of MSDE.
    13·1 answer
  • 1.6 code practice: question 1 edhesive
    12·2 answers
  • How have productivity programs improved the professional lives of people? (check all that apply)
    8·2 answers
  • What videos do you think we should make next?
    9·1 answer
  • Use the drop-down menus to complete each statement. Two main versions of Outlook are the desktop app and the app. The has limite
    15·2 answers
  • 3. Special keys labelled Fl to F12.
    8·1 answer
  • How to implement switch statement in Python?
    11·2 answers
  • How does information promote cooperation and Industry please explain​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!