RU beehive logo ITEC dept promo banner
ITEC 120
2010fall
ibarland

homeinfolectslabsexamshws
tutor/PIsObject120 + its docsjava.lang docsjava.util docs

lab04a
nested if-else
donuts and fritters

“It pays to buy in bulk, at Bulk-o-Mart's bakery!”

/** Some bakery price-calcuating functions.
 * @author ???
 * @see http://www.radford.edu/~itec120/2010fall-ibarland/Labs/lab04a.html
 */
class Bakery extends Object120 {


  /** Return the cost for multiple bakery items, in cents.
   * @param itemName The product being ordered; must be either "donut" or "fritter".
   * @param count The number items being ordered.
   * @return the list price for `count` `itemName`s, including any discounts, *in cents*.
   */

   // (Add your code here, *after* filling in the test cases below.)



  /** Test the above function. */
  static void testPrices() {
    System.out.println( "0 donuts:" );
    System.out.println( "Actual: " + orderPrice( "donut", 0 ) );
    System.out.println( "Expect: ???" );
    System.out.println( "1 donut:" );
    System.out.println( "Actual: " + orderPrice( "donut", 1 ) );
    System.out.println( "Expect: ???" );
    System.out.println( "2 donuts:" );
    System.out.println( "Actual: " + orderPrice( "donut", 2 ) );
    System.out.println( "Expect: ???" );
    System.out.println( "10 donuts:" );
    System.out.println( "Actual: " + orderPrice( "donut", 10 ) );
    System.out.println( "Expect: ???" );
    System.out.println( "100 donuts:" );
    System.out.println( "Actual: " + orderPrice( "donut", 100 ) );
    System.out.println( "Expect: 6175" );  // 6500¢ less 5% (325¢)

    System.out.println( "0 fritters:" );
    System.out.println( "Actual: " + orderPrice( "fritter", 0 ) );
    System.out.println( "Expect: ???" );
    System.out.println( "1 fritter:" );
    System.out.println( "Actual: " + orderPrice( "fritter", 1 ) );
    System.out.println( "Expect: ???" );
    System.out.println( "2 fritters:" );
    System.out.println( "Actual: " + orderPrice( "fritter", 2 ) );
    System.out.println( "Expect: ???" );
    System.out.println( "4 fritters:" );
    System.out.println( "Actual: " + orderPrice( "fritter", 4 ) );
    System.out.println( "Expect: ???" );
    System.out.println( "100 fritters:" );
    System.out.println( "Actual: " + orderPrice( "fritter", 100 ) );
    System.out.println( "Expect: ???" );

  }

}
Notes:

If you finish...

Go ahead and add one more case:

Where will you fit a third case into the if-else statement? (There are several possible ways; we'll also talk about if-else-if statements in lecture soon.)

homeinfolectslabsexamshws
tutor/PIsObject120 + its docsjava.lang docsjava.util docs


©2010, Ian Barland, Radford University
Last modified 2010.Sep.23 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme