class Bakery extends Object120 { /** Return the cost of a donut order, in cents. * @param numDonuts The number of donuts being ordered. * @return the list price for `numDonuts` donuts, including any discounts, *in cents*. */ static int donutOrder( int numDonuts ) { int unitPrice; unitPrice = 65; double discount; if (numDonuts >= 10) { discount = 5.0 / 100.0; } else { discount = 0; } return toInt( (unitPrice*numDonuts)*(1-discount) ); } /** Return the cost of a donut order, in cents. * @param numDonuts The number of donuts being ordered. * @return the list price for `numDonuts` donuts, including any discounts, *in cents*. */ static int fritterOrder( int numFritters ) { int basePrice = numFritters*110; double discount; if (numFritters >= 4) { discount = 0.10; } else { discount = 0.00; } return toInt(basePrice*(1-discount)); } /** The price of an order, in cents. * @return the price of an order, in cents. * @param itemName *must* be either "donut" or "fritter". * @param count is the number of pastries ordered. */ static int orderPrice( String itemName, int count ) { if (equals(itemName, "donut")) { return donutOrder( count ); } else if (equals(itemName,"fritter")) { return fritterOrder( count ); } /* else if (equals(itemName,"bear claw")) { return bearClawOrder(count); } else if (equals(itemName, "cupcake")) { return cupcakeOrder(count); } */ else { throw new RuntimeException("Whoah, this line shouldn't be reached."); } } static void testDonutOrder() { System.out.println( "== testDonutOrder ==" ); assertEquals( 0*65, donutOrder(0)); assertEquals( 1*65, donutOrder(1)); assertEquals( 2*65, donutOrder(2)); assertEquals( toInt( 10*65*0.95), donutOrder( 10)); assertEquals( toInt(100*65*0.95), donutOrder(100)); System.out.println(); // trailing newline return; } static void testOrderPrice() { System.out.println( "== testOrderPrice ==" ); assertEquals( 0*65, orderPrice("donut", 0)); assertEquals( 1*65, orderPrice("donut", 1)); assertEquals( 2*65, orderPrice("donut", 2)); assertEquals( toInt( 10*65*0.95), orderPrice("donut", 10)); assertEquals( toInt(100*65*0.95), orderPrice("donut", 100)); assertEquals( 0*110, orderPrice("fritter", 0)); assertEquals( 1*110, orderPrice("fritter", 1)); assertEquals( 2*110, orderPrice("fritter", 2)); assertEquals( toInt( 4*110*0.90), orderPrice("fritter", 4) ); assertEquals( toInt(100*110*0.90), orderPrice("fritter",100) ); System.out.println(); // trailing newline return; } static void testAll() { System.out.println( "==== testAll ====" ); testDonutOrder(); testOrderPrice(); System.out.println(); // trailing newline return; } }