home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.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:
-
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.).
-
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"
|
-
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.
-
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.
-
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.
-
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:
-
They tend to be more work (point-for-point) than regular homeworks.
-
They are not always as spelled out for you:
sometimes you'll want/need to write a method or include a field
even though the assignment doesn't explicitly say so.
-
They should be fully polished: make sure the documentation
really is descriptive, check for good grammar and spelling, etc..
Don't include fields/methods you never use.
(All this applies to ordinary homeworks too, but
we'll cut less slack for extra-credit homeworks.)
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs