|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
Work on today's lab with a partner. You can write the following two-to-three methods in a class named, say, ebayExpert.
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:
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. } } |
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!
You will be checked off on the above three problems
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. ↩
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2008, Ian Barland, Radford University Last modified 2008.Feb.05 (Tue) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |