RU beehive logo ITEC dept promo banner
ITEC 120
2008spring
ibarland,
jdymacek

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

lab02b
Spies and MCs
Javadoc; Strings

Today's project will be done in pairs.

Today we'll experiment with Strings -- Strings represent text. This is a third type of data, in addition to int and double.

Experimenting on Strings

Start up a new BlueJ project, named something like “lab02b”. In the code pad (the lower-right corner of the main screen1), type in some sample strings, such as:

  1. "hello"
  2. "Don't forget the quotation marks, else Java won't know it's a String."
  3. "!&$^%, and &*(# too!"
  4. ""
  5. Things get a bit more interesting if we use + to concatenate two Strings:
  6. "hi" + "there"
  7. "Ja" + "va a la" + "ng" + "u" + "age."
  8. Exercise: together as a class, we'll complete the following function, using + for Strings:

    /** Return the sound of an echo, of a given phrase.
     *
     * @param _____ The phrase to shout at a cliff-side.
     * @return The sound returned
     *  
     * Examples, presuming that `mc` is an instance of Emcee:
     *    mc.echo2( "hello" ) = "hello, hello."
     *    mc.echo2( "Who's there?" ) = "Who's there?, Who's there?."
     *    mc.echo2( "z" ) = ______
     *    mc.echo2( "" )  = ______
     */
    _____ echo2( _____ _____ ) {
      return ____________________________;
      }
    

Today's task

Solution

Challenge problem (optional)

Some people wonder, how Bond's standard introduction can be modified for people with three names — say, Lewis Scooter Libby.


1 If you don't see such a pane, select View > Show Code Pane.      

2 I don't suggest using this introduction at real-life cocktail parties; it only works in movies.      

3The right-associative version, or the left-associative? (resp.)      

4This difference isn't some left-vs.-right preference of the universe; it just stems from the fact that the "Bond-James-Bond" algorithm uses its right input twice, but the left input only once.      

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2008, Ian Barland, Radford University
Last modified 2008.Jan.29 (Tue)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme