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

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

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

Today you will continue lab02a—applying the design recipe: books-a-jillion, (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, go back and implement a correct solution.
  2. Raise your hand, and a (peer) instructor will come by and check off you and your partner. You must 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.

  3. 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.)
  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. (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 follow instructions from last week's lab to get it into your project (and you'll have class Bookstore extends Object120).

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


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