RU beehive logo ITEC dept promo banner
ITEC 120
2008spring
ibarland,
jdymacek

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

lab04a
booleans, if, predicates
eBay fees

Work on today's lab with a partner. You can write the following two-to-three methods in a class named, say, ebayExpert.

Booleans as inputs: Calculating eBay fees

If you sell an item on eBay, you are charged a fee. That fee partly depends on how much the item sold for (its “sale price”); there is also a flat fee just for using eBay to start with, as well as an optional extra fee if you want some fancy pictures in your listing. More precisely, eBay's fee structure is1:

  1. $0.20 (the flat “insertion fee” — we presume all good auctions start the bidding at a penny2 (or better, at 0)), plus...
  2. an optional $0.35, “gallery” fee — this applies only if you upgraded to include extra pictures in your listing — plus...
  3. 5.25% of the (up to) first $25 of the sale price, and 3.25% of the rest of the sale price. (They call this the “final value fee”, if you care.)
Note that eBay occasionally updates their fee structures (such as on 2008.Feb.20).

  1. Make a new BlueJ Project for lab04a, make a new class EbayExpert, and paste in the following:
    class EbayExpert {
    
      // Some named constants:
      double INSERTION_FEE = 0.20;  // A flat fee for all listings.
      double PICTURE_FEE   = 0.35;  // The *potential* cost for using a picture ("gallery").
      
      double FV_THRESH_LOW = 25.00; // Final Value threshhold between 'low' and 'medium' rate.
      double FV_RATE_LOW = 0.0525;  // Final Value rate, applies up to FV_THRESH_LOW.
      double FV_RATE_MED = 0.0325;  // Final Value rate, applies after FV_THRESH_LOW.
    
    
      /** computeEbayFee computes the *total* cost which eBay charges to a seller,
       *   in dollars.
       *  @param salePrice    _______________
       *  @param usedGallery  _______________
       *  @return _____________________, in dollars.
       *   Some test cases (assuming ee is an ebayExpert):
       *      ee.computeEbayFee( ____, ____ ) = _____
       *      ee.computeEbayFee( ____, ____ ) = _____
       *      ee.computeEbayFee( ____, ____ ) = _____
       *      ee.computeEbayFee( ____, ____ ) = _____
       */
      ______ computeEbayFee( ______ salePrice, _______ usedGallery ) {
        return 12.34;  // A dummy, stub result.
        }
    
    
      /** computeFVFee computes the final-value fee which eBay charges to a seller.
       *  @param ________  _______________
       *  @return _____________________, in dollars.
       *   Some test cases (assuming ee is an ebayExpert):
       *      ee.computeFVFee( ____ ) = _____
       *      ee.computeFVFee( ____ ) = _____
       *      ee.computeFVFee( ____ ) = _____
       *      ee.computeFVFee( ____ ) = _____
       */
      ______ computeFVFee( ______ _______ ) {
        return 56.78;   // A dummy, stub result.
        }
    
    
    
      }
    
  2. As always, work through the test cases (We will do some in class, and you'll need to do some on your own), and fill out the javadoc and function signatures for both computeFVFee and computeEBayFee.
  3. Write the function body for computeFVFee, and test it.
    You should use the named constants provided, rather than have magic numbers like 25.00 and 0.0525 embedded in your code, which (from an onlooker's perspective) seem to make your code give the correct answers like magic.
  4. Write the function body for computeEbayFee, and test it.
    Use local variables, if you need to compute a sub-result. Use the named constants provided, rather than magic numbers.
  5. The above problem was simplified a bit; eBay's final-value-fee doesn't have just the two tiers (0.00, 25.00] and (25.00,+∞), but actually three: (0.00,25.00], (25.00,1000.00], and (1000.00,+∞). Those round and square parentheses are math-ese for intervals with open and closed endpoints; eBay presents this same information in a table.
    Go back and change your program to use eBay's actual final-value-fee. Introduce named constants as appropriate.

    Use the if-else-if statement, for this three-tier problem. Match up those curly-brackets carefully!

  6. You will be checked off on the above three problems

  7. Optional:

    In your test cases, you noticed that if the item sold for a small price, the ebay fee can actually exceed what the item sold for, and the seller actually lost money on the auction (!). Write a function wasAuctionProfitable, which returns a boolean: it returns true if the seller made a penny or more, and it returns false if the seller lost money (or broke even).
    There is nothing particularly special about the fact that the return type is boolean; you can look at the example from lecture, mustRegisterForDraft.

    We want this function to work — without modification — even if eBay totally revamps their pricing structure. (That would require rewriting ebaySellerFee, but it shouldn't require rewriting wasAuctionProfitable. Yay, for no repeated code!)

    Of course, as per The Design Recipe, we want the function's signature, javadoc comments, and test cases, as well as the body of the function.

Expect homework/exam questions like “How are named constants written differently from local variables?” and “Conceptually, how is a named constant different from a local variable?”, and/or some examples of code asking you to attach a name to some value.


1 We are simplifying the problem a bit: we assume that your starting price is a penny — really, eBay should allow for the starting price of zero, if you ask me — and for our purposes we slightly simplify the final value fee. See the optional problem, below.      

2 If one purpose of an auction is to let buyers determine a fair market-price, then theoretically the seller shouldn't have any say in setting the price. Of course, it's fair for a seller to have a reserve price, which they won't sell below.      

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2008, Ian Barland, Radford University
Last modified 2008.Feb.05 (Tue)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme