The purpose of today's lab is...
More practice with programming without Becker's robots
String manipulation
More practice with instance variables and accessors/mutators
Console I/O
Scanner
Use the Java API
In today's lab we will write a program that can reverse the letters in each word in a simple sentence. For example, "The dog sat." becomes "ehT god tas.".
Create a class, Sentence, that represents a sentence that can be reversed. Also create a driver that can interact with the user and use your Sentence class.
This class should have 2 instance variables:
normalSentence - A normal sentence with a period at the end and no other punctuation
reversedSentence - The normalSentence with each word in the sentence reversed
Create accessors and mutators for each variable.
Provide a public method, reverseSentence, that can reverse each word in a simple sentence. You can assume that each word will be separated by exactly one space, there will be a period at the end, and there will be no other punctuation. As a first step to writing this function you should check out the Java API for String: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html. Use pseudocode and stepwise refinement.
HINT: You can use Scanner not only to read input from System.in (standard input), but also a String.
Create a driver that will instantiate a Sentence object and interact with the user to get a sentence and display the results of reversing (see sample output below).
Welcome to the sentence reverser!
Please enter a simple sentence to reverse:
I saw a cat.
You entered: I saw a cat.
Reversing...
The reversed sentence is:
I was a tac.
Thank you for using my sentence reverser. Goodbye.
Show your program to your TA when you are done and submit it to the dropbox at https://cse.sc.edu.