Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions