RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

hw02
Strings, functions, booleans
shortened greetings

Turn in a hard copy, and attach your Emcee.java to the D2L, hw02-dropbox. Due Sep.17 (Mon) 23:59.

  1. Make a class class Emcee extends Object120, (importing Object120 as discussed in the start of lab01b—Strings: and setup: H: drive; Object120.java).
  2. Optional/encouraged: Add an opening javadoc comment which includes at least one sentence and your name as an @author. See examples of code from lab/lecture (e.g. Pizzeria.java.) In BlueJ, you can choose Documentation in the upper-right to view the documentation and see if it's correct. You can
  3. Make the function shorten, which takes in somebody's last and first name (in that order), and returns a shortened form of their name: their initials. For example, shorten( "Rogers", "Fred" ) should return "F.R.". However, if the first and last initial are the same then return that letter followed and apostrophe and ‘s’: shorten( "Brummel", "Beau" ) should return "B's".

    Be sure to look at the Object120 documentation, to find helpful functions for extracting a letter from a string, etc.. (You can look at Object120 documentation in BlueJ, choosing Documentation instead of Source Code from the upper-right corner, or if that doesn't work you can follow link at the top of this web-page.)

    Follow the usual steps:

    1. (4pts) Write a signature for this function and a stub implementation.
    2. Optional: Write Javadoc for the function, including @param and @return tags appropriately. (See programs in lab/lecture notes for examples.)
    3. (4pts) Write test cases. We will always assume that names contain at least one character. (So you don't need any tests for the empty string, however you should include one test for names with one letter, e.g. Malcom X.)
    4. (7pts) Then, complete the function body (removing the stub body from step (i)).

      heads-up: When you check if two initials are equal: use == if comparing chars, but use boolean Object120.equals(String,String) if comparing Strings. (I suspect using chars is a more natural fit for this problem, but there are also reasonable approaches using Strings.)

  4. Make a second Emcee function, greetFriend, which takes in last and first name, and returns a greeting for that friend. The greeting must include their shortened name, converted to lower case1. For example, Fred Rogers might be greeted by “Yo, f.r. -- wassup?”. (If you want to have greetFriend answer with some pattern besides “yo ... wassup” that's fine. Follow the same steps (a)-(d) as before (15pts). When writing the function body, do not repeat any previous code from shorten; instead call that already-existing function if you want to use a shortened name, just like it were a conveniently built-in Java function!

1See String Object120.toLowerCase(String).      

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2012, Ian Barland, Radford University
Last modified 2012.Sep.13 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme