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 are minimum computer requirements for a software program?
Bumek [7]
<span><span>Operating system: Windows 2000/XP
</span><span>CPU: Pentium 4 1.5 GHz or Athlon XP 1500+ processor or higher
</span><span>Memory: 384 MB RAM</span></span>
8 0
4 years ago
Computer program allowing the computer to communicate<br> with a hardware device
Airida [17]

Answer:The software that allows a computer to communicate with hardware devices is referred to by the general term known as 'Drivers.

Explanation:Transmission Control Protocol/Internet Protocol (TCP/IP) is the backbone of the Internet and the true language computers use to talk to each other. Essentially it's a set of standards for sending information from a computer's network card, through transmission lines to another network card.

8 0
3 years ago
Discuss five domains of Instructional technology​
Effectus [21]

Answer:

Design, Development, Utilization, Management, and Evaluation.

7 0
3 years ago
What dialogue box is used for character formatting?
valentinak56 [21]

Examples of character formats that can be applied to text characters in Word include those you find in the Font dialog box (such as bold, italic, underline, font, size, color, superscript, subscript, scaling, animation effects, etc), highlight, change case, etc. To apply a character format to a character or a set of characters, you need to specifically select the desired amount of characters and then apply the formatting you want.

5 0
3 years ago
A database has a built-in capability to create, process and administer itself.
kherson [118]

Answer:

false

Explanation:

6 0
3 years ago
Other questions:
  • Why we can't install a 64 bit software on a 32 bit computer??
    5·1 answer
  • In setting up a small office network, the network administrator decides to assign private IP addresses dynamically to workstatio
    12·1 answer
  • I need help with this​
    7·1 answer
  • Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Els
    9·1 answer
  • Which of the following is not a major reason for an email bounce?
    8·1 answer
  • Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt and wri
    13·1 answer
  • Smileys Pizzeria has a special on cheese pizza this month. 6- inch personal pizzas are $5, 10-inch small pizzas are $8, 14-inch
    6·1 answer
  • Which of the following is the correct financial function that returns the periodic payment for a loan?
    10·1 answer
  • What are the uses of DVD Ram​
    12·2 answers
  • A user calls the help desk to report that a mobile device exhibits very slow performance. What could cause this problem
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!