RU beehive logo ITEC Department logo
ITEC 120
2007spring
ibarland,
jpittges

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

hw-ec02-ebayRevisited
extra credit homework: Ebay Fees, revisited
hw-ec02; 20pts; Due Mar.23 (Fri) 17:00

Rewrite the eBay Auction Fee problem (complete with three tiers, named constants, and an if-else-if for the final value fee), with the following guides:

  1. Instead of writing just one big function, write three helper functions (one for each of the three types of fees). Include test cases and comments for each. Note that the listing fee, a flat fee, will be a constant-function. Your overall function computeEbayFee will call each of those three other small functions.

    For the final-value-fee: each of the three tiers of this particular fee, use two named constants (perhaps named something like THRESHOLD1,COMMISION1, etc.).

  2. Write a function ebayFeeReceipt, which returns a string detailing the total cost, along with each sub-fee. This string should be suitable for inserting into an email or a web page. For example, for an item which sold for $35.00, you might have
    ebayFeeReciept( 35.00, true ) =
    " $35.00 sales price
    -$0.10 listing fee
    -$0.35 gallery usage fee
    -$1.61 final value fee
    --------
     $32.94     net sales price"
        
    1. The final value fee is always rounded down to the nearest penny.
      Hint: you might find it convenient to do all your internal work in cents, so you can use ints, and not have to worry about round-off errors. If you need to call a function to convert a doubles and ints, you can either use code like “(new Double(2.99998)).intValue()”, or you can use casting.
    2. Note that you'll want to make sure the cents is displayed as exactly two digits. (We have seen this a couple of times -- exam1's pad2 or the book's getDisplayValue in Chapter 3.) Having a helper-function “centsToString” might be handy, to avoid having repeated code!
      Another hint: How to round down in the hundredths place, when rounding-down-to-integer is what Double's intValue does? Try multiplying by 100, then round down, then undo the multiplication.
    3. It's a bit problematic, how to represent newline characters for input and output. When writing your program, recall that \n is the newline character, which you can use in your Java String literals. When BlueJ displays a String containing a newline, the way the character is displayed depends on the context:
      • If you call a function interactively in BlueJ, it shows the resulting string, rendering newlines as “\n”.
      • If you evaluate it in the Code Pad, then the newlines are rendered as actually moving to the following line, although BlueJ's indentation gets a bit confused.
      • You can also pass your result to System.out.println, which takes a String and displays it on the console window.
  3. Discuss, 1-2 short paragraphs: What are the pros and cons of writing one big function which computes the total fee, vs. three small functions which each compute just part of the fee? Be sure to take into account future methods you might want to add to the class EBayExpert.

A general note on extra-credit homeworks:

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2007, Ian Barland, Radford University
Last modified 2007.Aug.27 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme