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]
2 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]2 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
A(n) ______ is system software.
arsen [322]
System software<span> is a type of computer program that is designed to run a computer's hardware and application programs. If we think of the computer </span>system <span>as a layered model, the </span>system software<span> is the interface between the hardware and user applications</span>
7 0
3 years ago
Help ASAP!!! During which phase of a well-structured study session is each occurring?
gladu [14]

Answer:

1. drill

2. discuss

3. review

4. prepare

Explanation:

Your Welcome!

7 0
2 years ago
Read 2 more answers
If you must transmit a file over an insecure channel, one way to prevent its contents from being seen by someone who might inter
natali 33 [55]

Answer:

connect to the network from a remote location using a VPN.

Explanation:

VPN stands for virtual private network, it allows computers to establish a secure connection through an encrypted tunnel for exchanging data between two end points when communicating through insecure channels like the internet.

8 0
3 years ago
According the text book the information system at first disseminate and then collect, store, process, and analyze the informatio
konstantin123 [22]

Answer:True

Explanation:

The above mentioned statement is correctly explaining the procedure of Information system

4 0
3 years ago
What important piece of software controls the computer's hardware and software resources?
AnnZ [28]
The control panel controls the adding or subtracting of hard or software.

3 0
2 years ago
Other questions:
  • What kind of firewall can block designated types of traffic based on application data contained within packets?
    7·1 answer
  • Store programming components in the shared folder. you want to secure the data in the folder as follows: members of the research
    11·1 answer
  • Can someone please answer this for me ? What is data centre virtualization?
    10·1 answer
  • Prostate cancer can physically affect both men and women
    5·1 answer
  • If you change a column header in your data source, what would you press to ensure that the data is synced as expected?
    11·1 answer
  • Difference between ancient and modern mode of information <br> transmission
    12·1 answer
  • 1. True or false: The more pixels per inch in an image, the higher the resolution is. (1 point)
    8·1 answer
  • In some video games, the player cannot obtain the reward without doing what with something that they already have?
    5·1 answer
  • THIS IS TIMED PLS HURRY UP
    7·1 answer
  • Big Data _______________. Relies on the use of unstructured data imposes a structure on data when it is captured relies on the u
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!