Question: Using Java: Write a program that asks the user to enter a sentence. Using matches method using only one pattern validate that the entered sentence

Using Java: Write a program that asks the user to enter a sentence. Using matches method using only one pattern validate that the entered sentence consists only of letters and ends with either: a period, an exclamation mark, or a question mark. To check if the given string represents a valid sentence define a pattern. If it is not a valid sentence, your program should output that the input is not valid. Otherwise the input should be displayed with all the vowels replaced with an #character

The following shows sample runs of the program:

Run #1 
Please enter a sentence that consists of letters only and ends with a period, an exclamation mark, or a question mark 
 
 The first sentence is not valid 
The entered input "The first sentence is not valid" is not a valid. 

Run #2

Please enter a sentence that consists of letters only and ends with a period, an exclamation mark, or a question mark 
 
 The 2nd sentence is also invalid! 
The entered input "The 2nd sentence is also invalid!" is not a valid. 
Run #3 
Please enter a sentence that consists of letters only and ends with a period, an exclamation mark, or a question mark 
 
 A very NICE sentence. 
The entered input: "A very NICE sentence." 
with all vowels replaced is: "# v#ry N#C# s#nt#nc#." 

Run #4

Please enter a sentence that consists of letters only and ends with a period, an exclamation mark, or a question mark 
 
 Do you like programming? 
The entered input: "Do you like programming?" 
with all vowels replaced is: "D# y## l#k# pr#gr#mm#ng?" 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!