|
home—info—lects—labs—exams—hws
textbook—tutor/PIs—java.lang docs—java.util docs
Previously, wrote code to compute the final value fee for eBay auctions. However, there are more types of fees:
Gallery fee: If your auction uses “GalleryPlus”1 to include many pictures, then the gallery fee is $0.35. Otherwise, the gallery fee is zero.
Write a method totalFee, which includes the final value fee, and the gallery fee (which might be zero, remember), and a flat “insertion fee”2 of $0.10.
Don't repeat code: your code should call finalValueFee and galleryFee (using them as helper functions!). Your method body should not be more than three lines (and might be as little as one line).
If you think about it, you'll realize that it's conceivable that you might lose money on an auction (for instance, if an item sells for a nickel, then you definitely didn't even recoup the flat listing fee, much less any gallery fee).
Write a method wasProfitable, which returns whether or not the sale price was more than all the fees incurred.
As before, don't repeat any code; instead call methods you wrote previously.
class EbayExpertTester { public static void main( String[] args ) { EbayExpert ee = new EbayExpert(); System.out.println( "Testing computeFVFee" ); System.out.println( ee.computeFVFee(0) + " expected $0.0" ); System.out.println( ee.computeFVFee(10) + " expected $0.875" ); System.out.println( ee.computeFVFee(25) + " expected $2.1875" ); System.out.println( ee.computeFVFee(35) + " expected $2.5375" ); System.out.println( ee.computeFVFee(1000) + " expected $36.3125" ); System.out.println( ee.computeFVFee(1010) + " expected $36.4625" ); System.out.println( "Testing galleryFee" ); System.out.println( ee.galleryFee(true) + " expected $0.35" ); System.out.println( ee.galleryFee(false) + " expected $0.0" ); System.out.println( "Testing totalFee" ); System.out.println( ee.totalFee(0,false) + " expected $0.1" ); System.out.println( ee.totalFee(10,false) + " expected $0.975" ); System.out.println( ee.totalFee(25,false) + " expected $2.2875" ); System.out.println( ee.totalFee(35,false) + " expected $2.6375" ); System.out.println( ee.totalFee(1000,false) + " expected $36.4125" ); System.out.println( ee.totalFee(1010,false) + " expected $36.5625" ); System.out.println( ee.totalFee(0,true) + " expected $0.45" ); System.out.println( ee.totalFee(10,true) + " expected $1.325" ); System.out.println( ee.totalFee(25,true) + " expected $2.6275" ); System.out.println( ee.totalFee(35,true) + " expected $2.9875" ); System.out.println( ee.totalFee(1000,true) + " expected $36.7625" ); System.out.println( ee.totalFee(1010,true) + " expected $36.9125" ); System.out.println( "Testing wasProfitable" ); System.out.println( ee.wasProfitable(0,false) + " expected false" ); System.out.println( ee.wasProfitable(0,true) + " expected false" ); System.out.println( ee.wasProfitable(0.25,false) + " expected true" ); System.out.println( ee.wasProfitable(0.25,true) + " expected false" ); System.out.println( ee.wasProfitable(0.45,false) + " expected true" ); System.out.println( ee.wasProfitable(0.45,false) + " expected true" ); System.out.println( ee.wasProfitable(0.49,true) + " expected false" ); System.out.println( ee.wasProfitable(0.49,true) + " expected false" ); System.out.println( ee.wasProfitable(0.50,false) + " expected true" ); System.out.println( ee.wasProfitable(0.50,true) + " expected true" ); System.out.println( ee.wasProfitable(10,true) + " expected true" ); System.out.println( ee.wasProfitable(10,false) + " expected true" ); } } |
You may use your previous code for the Final Value Fee; if you didn't finish that, here is a version you can use:
class EbayExpert { /** computeFVFee computes the final-value fee which eBay charges to a seller. * @param salePrice How much the item was auctioned for. * @return The Final Value Fee, in dollars. */ double computeFVFee( double salePrice ) { final double FV_THRESH_LOW = 25.00; // Final Value threshhold between 'low' and 'medium' rate. final double FV_THRESH_MED = 1000.00; // Final Value threshhold between 'medium' and 'high' rate. final double FV_RATE_LOW = 0.0875; // Final Value rate, applies up to FV_THRESH_LOW. final double FV_RATE_MED = 0.0350; // Final Value rate, applies after FV_THRESH_LOW. final double FV_RATE_HIGH = 0.0150; // Final Value rate, applies after FV_THRESH_MED. if (salePrice <= FV_THRESH_LOW) { return FV_RATE_LOW * salePrice; } else if (salePrice <= FV_THRESH_MED) { return FV_RATE_LOW * FV_THRESH_LOW + FV_RATE_MED * (salePrice - FV_THRESH_LOW); } else { return FV_RATE_LOW * FV_THRESH_LOW + FV_RATE_MED * (FV_THRESH_MED - FV_THRESH_LOW) + FV_RATE_HIGH * (salePrice - FV_THRESH_MED); } } } |
1 EBay lists this under “Listing Upgrade Fees” ↩
2Well, it's only a flat fee for auctions whose starting price is a penny. But really, all auctions should start there, and let the market determine the price, without any input from the seller. ↩
home—info—lects—labs—exams—hws
textbook—tutor/PIs—java.lang docs—java.util docs
©2009, Ian Barland, Radford University Last modified 2009.Mar.25 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |