RU beehive logo ITEC dept promo banner
ITEC 120
2019fall
asbrennem
ibarland

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 the design recipe, and refer to that lecture's pizzaArea example.

You will turn in today's work on D2L (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 )
 *     = "Books-A-Jillion: we stock 6 copies of Slaughterhouse 5, guaranteed!"
 *   bookstoreAd( "", 1984 )
 *     = "Books-A-Jillion: we stock 1985 copies of  1984, guaranteed!"
 *       (Hmm, an extra space there, in the book-title...)
 *
 *
 * (Btw: Slaughterhouse 5 is by Kurt Vonnegut; 1984 is by George Orwell.)
 */

  1. Open a new project in BlueJ (say, lab02a), and then create a new class (say, class Bookstore).
  2. Delete the auto-provided code, and replace it with:
    class Bookstore {
        
        
        
    }
      
    You'll put all of today's work between those two curly-braces (just like we did in class Pizzeria { }).
  3. Read the examples of bookstoreAd shown above, and understand (a) what information is being given to the function, and (b) what is the answer returned by the function?
  4. 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
      • Fahrenheit 451
      • Population: 485
      • 21
      • 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.
  5. Signature: Write the signature for your method.
  6. 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.
  7. 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 Bookstore.bookstoreAd from Code Pad, but it will of course give the dummy answer for now. Similarly, you can call your Bookstore.testAds function, and it should print answers that don't (yet) match the desired-results.

  8. Both you and your partner
  9. 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!
  10. If you finish: We saw briefly in 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.


logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.