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
Jeffrey works with a huge database of spreadsheet records each day. To organize and identify these spreadsheets, he wants to ass
mariarad [96]

Answer:

A. Document Properties

B. Permission

C. Document Options

D. File Details

The answer to this question is "File Details " . This will help Jeffrey works efficiently with a huge database of spreadsheet records each day. He can assign names to these File Details which represents each spreadsheet records. This will help his report more organized and easy to identity.

8 0
3 years ago
You are now going to prepare some reports for the company. Measurements are in metres and volume
romanna [79]

if you follow me and like and mark in brainliest answer only I will tell the answer

4 0
2 years ago
The automotive system that connects the engine and the transmission to the wheels is called the
insens350 [35]
I believe the driveshaft 

8 0
2 years ago
The remove() method in the Queue interface ________. Group of answer choices retrieves, but does not remove, the head of this qu
salantis [7]
<h2>Question:</h2>

The remove() method in the Queue interface ________.

A. retrieves, but does not remove, the head of this queue, returning null if this queue is empty

B. retrieves and removes the head of this queue, or null if this queue is empty

 

C. retrieves, but does not remove, the head of this queue, throwing an exception if this queue is empty

D. retrieves and removes the head of this queue and throws an exception if this queue is empty

<h2>Answer:</h2>

D. retrieves and removes the head of this queue and throws an exception if this queue is empty

<h2>Explanation:</h2>

In Java, the Queue interface is found in the java.util package and inherits from the Collection interface. It is used to store elements which are processed in the order in which they are inserted. This means that the first element will be processed first.

The Queue interface has many methods. Some of them are;

i. add(): allows elements to be added to the queue.

ii. remove(): retrieves and removes elements from the head of the queue. The head of the queue points to the first element of the queue. If the queue is empty, the remove() method throws an exception called the <em>NoSuchElementException</em>

<em />

iii. poll(): retrieves and removes the element at the head of the queue. Unlike the remove() method, if the queue is empty, a <em>null </em>is returned.

iv. peek(): retrieves but does not remove the element at the head of the queue. Just like the poll() method, a <em>null</em> is returned if the queue is empty.

7 0
2 years ago
Which of the following is true of the poka-yoke approach used for mistake-proofing processes?
Svetradugi [14.3K]

Answer:  b)It helps to engage workers in continuous improvement activities.

Explanation: Poke-yoke method was the technique to eliminate the mistakes that happen in a manufacturing process. It helps in avoiding the issues in the product and correcting those errors.

Mistake proofing is the mechanism of this methods that ensures about the product manufactured is safe from any failure and defects.It alerts the workers to improve the product through their working.

Other options are incorrect because it was developed by Shigeo Shingo , they had easy mechanism and feedback system did not told the workers about defects.Thus, the correct option is option(b).

7 0
2 years ago
Read 2 more answers
Other questions:
  • #TODO: Define a data structure to keep track of which links are part of / not part of the spanning tree.
    14·1 answer
  • Your new home has a vacuum system. what kind of computer is controlling it?
    5·1 answer
  • Write a method that take an integer array as a parameter and returns the sum of positive odd numbers and sum of positive even nu
    13·1 answer
  • The idea behind ____ is that the peripheral can simply be plugged in and turned on, and that the computer should dynamically rec
    10·1 answer
  • Chen needs to configure a filter on the current folder and would like to filter by the sender of a message. Which tab in the Fil
    7·2 answers
  • You have created a new dhcp scope with address range 192.168.1.1 to 192.168.1.254. you have five servers configured with static
    9·1 answer
  • What are the most commonly found items in the trash according to the Municipal Solid Waste report?
    12·2 answers
  • State True or False: 1. Application software can run without the presence of system software. 2. . A language processor translat
    14·1 answer
  • Match the parts of the website address with its correct explanation. http://www.usa.gov/Agencies/federal.shtm/​
    5·2 answers
  • HELP ME PLEASE 41 PTS
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!