RU beehive logo ITEC dept promo banner
ITEC 120
2010fall
ibarland

homeinfolectslabsexamshws
tutor/PIsObject120 + its docsjava.lang docsjava.util docs

hw02
Strings, functions, booleans
shortened greetings

Part (a), due Sep.17 (Fri) by class

On WebCT > assessments, complete the questions for hw02a. (Note how WebCT shows that you have one attempt and 30min to complete the questions after you start. There are 15 questions, similar in style to the hw02a-practice (which you can repeat as many times as you like, not for a grade, with no time limit). You will not submit any hardcopy.

If you notice a typo or mistake in a question, please let me know.

Reading: § 5.1, and §5.2 up until (but not including) "Conditional Operator".

Part (b), due Sep.20 (Mon) by class

Turn in a hard copy, and attach your Emcee.java to WebCT > assessments > hw02b.

  1. Make a class class Emcee extends Object120, (importing Object120 as discussed in the start of lab01b—Strings).
  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 first 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".

    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. -- whazzup?”. (If you want to have greetFriend answer with some pattern besides “yo ... whazzup” 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 function if you want to use a shortened name.

1See String Object120.toLowerCase(String).      

homeinfolectslabsexamshws
tutor/PIsObject120 + its docsjava.lang docsjava.util docs


©2010, Ian Barland, Radford University
Last modified 2010.Sep.30 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme