15-100: Introductory/Intermediate Programming (Section F)
Fall 2006
Exercise   
10/23/2006
Modify Names
Due:  Monday, October 30
8am

Relevant Reading:

  • API on Random and String classes

Assignment:  (worth 10 exercise points)

Get the ex10-23.zip file.  Write a program that asks the user for a  phrase (all entered into one JOptionPane inputDialog).    The program should then:

  • display how many characters are in the phrase (including spaces and punctuation).
  • display how many words (defined as "between spaces") are in the phrase.
  • display in the console window the phrase, one word per line.
  • display in the console window the phrase, with all spaces replaced by commas.
  • display how many vowels are in the phrase (be sure to count both upper and lower case).
  • display the phrase with the characters in backwards order.
  • display the phrase with the last word first, followed by all of the other words.
  • display the phrase with the characters jumbled up.  IE.  Write out the same number of characters as in the original string, but pick a random character from the string each time.  (See the example below.)
  • display the phrase with the words (defined as "between spaces") in backwards order:


NOTES:  If you wish, your entire code can be in the Application.java file.


Example
INPUT:   Now is the winter of our discontent.

OUTPUT:

The phrase has 36 characters.

The phrase has 7 words.

The phrase one word per line:
Now
is
the
winter
of
our
discontent.

Replace spaces with commas:
Now,is,the,winter,of,our,discontent.

There are 11 vowels in the phrase.

Backwards:
.tnetnocsid ruo fo retniw eht si woN

Last word first:
discontent. Now is the winter of our  // note that the period was part of last "word".  That's okay.

A random selection of characters:
w oiititoe.wrntfN nfwoui dNscfnwrnti   // of course, here the output could be different.

Words in backwards order:
discontent. our of winter the is Now


Extra Credit:
When outputting the random selection of characters, make sure that each character appears only as many times as it does in the original.  For instance, in the example above, the letter e only appears twice in the input.  Thus, e should appear exactly twice in the output.
Handin:
  • Be sure to read the general handin instructions on the exercises page.
  • Rename the folder containing all of the files to be "lastname-firstname-100SectionLetter-phrase".   For example, if I were in Section Z, I would rename my folder to be:  "McElfresh-Scott-100Z-phrase"  (without the quotes).   
  • Create a zip file of this folder, with the same name as the folder (except with the .zip ending this time). Instructions for zipping can be found in the system and software handouts linked on the main course page.
  • Submit this file via the electronic handin.  If you have problems, contact me.