RU beehive logo ITEC dept promo banner
ITEC 120
2009spring
ibarland
nokie
jmdymacek

homeinfolectslabsexamshws
textbooktutor/PIsjava.lang docsjava.util docs

lab07a
eBay fees
using if-else-if

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

Calculating eBay fees

If you sell an item on eBay, you are charged several different fees. Today, we will compute one of those: the “final-value fee”, which depends on how much the item sold for (its “sale price”).

(Note that 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. We'll handle those other fees in a future lab.) The final value fee is 8.75% of the (up to) first $25 of the sale price, and 3.50% of the rest of the sale price.

  1. Make a new BlueJ Project for lab07a, make a new class EbayExpert, and paste in the following:
    class EbayExpert {
    
      /** computeFVFee computes the final-value fee which eBay charges to a seller.
       *  @param ________  _______________
       *  @return _____________________, in dollars.
       */
      ______ computeFVFee( ______ _______ ) {
        return 56.78;   // A dummy, stub result.
        }
    
    
    
    
    
    
      }
    
  2. As always, first write a test-program which tests several inputs. Can you find test-cases that make your arithmetic easy, yet enough test-cases to convince you that any code passing your tests is always correct? (We will do some in class, and you'll need to do some on your own). Fill out the javadoc and function signatures for computeFVFee.
  3. Write the function body for computeFVFee, and run your test-driver.
  4. 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.

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


  5. If you finish…

    Modify your program to account for two additional fees:

    How can you combine the method for computing the final-value-fee with all these other fees? See if you can do it without needing to change your first method. You can use “this.methodName(args…)” to have your method call another method you wrote previously!

homeinfolectslabsexamshws
textbooktutor/PIsjava.lang docsjava.util docs


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