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

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

lab02a
applying the design recipe
books-a-jillion

Today you and your partner will write one method from scratch. To help you, follow the design pattern as discussed in lect02a—the design recipe: revisit: stub functions and test drivers, and refer back to lab01a's pizzaArea example.

You will turn in today's work on WebCT (both you and your partner), submitting everything but the actual function body. Note that you will turn in code with a stub-function and test cases, but not working code. You will lose points if you submit a working version!?! (I am trying to emphasize that you should write test cases before code; as our problems become more difficult this becomes more critical.)

Today's task

Write the following function bookstoreAd. We will follow the design recipe. Be sure to write a stub function and test cases, before completing the function.
/** Create an advertising slogan for our bookstore,
 * involving books whose name is words followed by a number,
 * like "Fahrenheit 451".
 * 
 * @param titleStart The first word(s) of the book.
 * @param num The number which completes the title.
 * @return An advertising slogan to make various posters with.
 * Examples:
 *   bookstoreAd( "Slaughterhouse", 5 )  // Vonnegut
 *     = "Books-A-Jillion: we stock 6 copies of Slaughterhouse 5, guaranteed!"
 *   bookstoreAd( "", 1984 )             // Orwell
 *     = "Books-A-Jillion: we stock 1985 copies of  1984, guaranteed!"
 *       (Hmm, an extra space there, in the book-title...)
 */

  1. Open a new project in BlueJ (say, “lab02a”), and then create a new class (say, “class Bookstore”).
  2. We'll follow the design recipe:
    1. Data Analysis: You and your partner identify: what pieces of information are used in this problem, and what Java types will you use for each?
    2. Test cases: Make a function static void testAds(), which calls your function and prints out the actual and expected results. Here are some other possible titles to use, as tests:
      • Mila 18 (Uris)
      • Fahrenheit 451 (Bradbury)
      • Population: 485 (Perry)
      • 21 (Iverson)
      • Catch-22 (Heller)
        (If you use this title, your function will presumably return a string without a hyphen; that's acceptable since the book-name doesn't quite match the pattern of the advertising campaign.)
  3. Signature: Write the signature for your method.
  4. Comments: You can just paste in the comment-block describing the problem into your code. The comment should be placed immediately above the function signature.
  5. Stub function: Complete the function body with some stub code -- just enough to get it to compile (not returning the correct answer!).

    At this point, you should be able to call your function from Code Pad, but it will of course give the dummy answer for now. Similarly, you can call your testAds function, and it should print answers that don't (yet) match the desired-results.

  6. Both you and your partner
  7. Finally, we can complete the design recipe:
    1. Complete the function body: go back and do the only part which requires creative thought: complete the body of the function bookstoreAd.
    2. Make sure your test cases all pass!
  8. If you finish: We saw briefly in lect01c—values; variables, how to use a local variable to store a sub-part of a computation.
    Can you make a version of your function which does this? (Or, if that's what you had already, can you make a version which doesn't use any variables?)

Note: On Thursday, we will continue this lab, and check it off for credit (you + your lab partner).
In general for the semester, some labs will be submitted or checked off, and others won't be. But keep in mind that all lab material is fair game for quiz, homework, and test questions.

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


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