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

homeinfolectslabsexamshws
tutor/PIsObject120 + 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 exaclty the same parter; 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

  1. Now that you have your test cases for bookStoreAd, go back and implement the correct solution.
  2. We saw in lecture yesterday, that function 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.)
  3. 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/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