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

variables vs one-big-return
finishing books-a-jillion

Today you will continue applying the design recipe, (though you don't need to work with exactly the same partner; if you don't just choose one or the other of your solutions to continue working on). If you didn't finish, you can use lab02a-soln-Bookstore.java. However, at this point, you should be able to come up with such test cases on your own. If it's not clear how to do this, stop by (peer) instructor office hours.

  1. Now that you have your test cases for bookStoreAd and a mere “stub” solution, go back and change the function's body to compute the correct solution. (That is, all your test-cases should pass.)
  2. We just discussed in the lab's intro, how bodies might be one big return statement like return substring(word, length(word)-3, length(word) );, or by a (helper) variable or two, to break the computation into more manageable bits:
          int endIndx;
          endIndx = length(word);
    
          int startIndx;
          startIndx = endIndex-3;
    
          return substring(word, startIndx, endIndx);
        
    You wrote your solution to bookStoreAd one way; now write it the other way. (Keep your first version there, but commented out. You can use “block comments” /* */ to comment out multiple lines of code.)

    You should use at least two local variables, and they should have a descriptive name.
    Hint: viewing the problem overall: what are two sub-parts of the overall ad/result, which you give a name to?

  3. You and your partner each submit your personal copy of your .java file.
    You should have a working bookStoreAd, and a test-function with at least 2 test cases. Also, your code must be well indented (like every sample code snippet shown in class or in the reading; see also BlueJ's Edit » Auto-layout).

    While waiting to be checked off, you and your partner can start on the next problems.

  4. Practice, writing a function from the top: Write salePrice, which takes in a book title and computes the sale price for the book according to the following rule: the price is $2, plus 25¢ per character in the title (including spaces), plus a 10% tax. So (for example), Mila 18 costs $4.125 ($2 + 25¢*7)*1.10. (We'll leave it as a problem for the sales clerks, how to make exact change for that.)

    Your solution should include at least three test cases (presumably chosen so that the answer is easy to compute w/o a calculator).

    Note: The length(String) lives inside class Object120; you'll need to (a) open that file; (b) right-click and save it locally on your H: drive; (c) use BlueJ’s Edit » Add Class from File… to get that local-copy into your project. Note that usually you don't need to repeat steps (a) and (b) ever again; however you'll want a slightly newer version of Object120 that I updated last weekend. (and, you'll have class Bookstore extends Object120).

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.