Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A program SentenceReverser that reverses the words in a sentence by reading words into a Stack until you find a period. Your program should then

A program SentenceReverser that reverses the words in a sentence by reading words into a Stack until you find a period. Your program should then pop off the words from the stack. Begin your reverse sentence with a capital letter and end it with a period. Your program should be able to handle multiple sentences. Use while (scan.hasNext()) to capture your input. Please no spaces before the period. Also, the first letter of your sentences should start with upper case.

Mary had a little lamb. His fleece was as white as snow.

Becomes:

Lamb little a had mary. Snow as white as was fleece his.

Note: Your test input should include multiple sentences as shown above. There should NOT be a space before your periods.

Hints:

1) The Scanner class can be used to break a String into a words using the space character as the delimeter.

public String reverse(String sentence) { String reversed = ""; Stack stack = new Stack<>(); Scanner scanner = new Scanner(sentence) // Get the words in a sentence while (scanner.hasNext()) { String pushWord = scanner.next(); // your code here. // Call a method processSentence when you find a period. } return reversed; public String processSentence(Scanner scanner, Stack stack, String reversed) { // your code here. }

2. How to remove space before a period.

popWord = popWord.replace(".", "");

3. Mask first letter of a word upper case:

String firstLetter = word.substring(0, 1); word = firstLetter.toUpperCase() + word.substring(1);

4. Make word all lower case:

word= word.toLowerCase();

Step by Step Solution

3.33 Rating (165 Votes )

There are 3 Steps involved in it

Step: 1

Heres the improved SentenceReverser program incorporating the provided hints and addressing potential issues Java import javautilScanner import javaut... 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

International Marketing And Export Management

Authors: Gerald Albaum , Alexander Josiassen , Edwin Duerr

8th Edition

1292016922, 978-1292016924

More Books

Students also viewed these Programming questions

Question

Derive Eq. (18.33) from Eq. (18.32).

Answered: 1 week ago