|
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
If you didn't check off lab03a last time, the peer instructor will come around and check you off at the start of class.
The bakery is happy with your work from lab03a (donutOrder).
They are adding fritters to their menu,
and they want you to add to your existing solution,
making a new function
They still offer a bulk discount, although fritters have a different threshold and discount amount than donuts do.
Notes:
Important: To compare twoFor example:String s in java, do not use== . Instead, useObject120.equals(··) .
Object120.equals( "howdy", "how"+"dy" ) Object120.equals( "howdy", Object120.toLowerCase("hOWdy")) String s; s = "how"; Object120.equals(s, s+""); // true // Here are some examples proving that `==` doesn't always work: s == s+"" // false!!1 "howdy" == Object120.toLowerCase("hOWdy") // false!! |
/** Some bakery price-calcuating functions. * @author ??? * @see http://www.radford.edu/~itec120/2012fall-ibarland/Labs/lab03b.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: " + donutOrder( 0 ) ); System.out.println( "Desired: " + ... ); System.out.println( "1 donut:" ); System.out.println( "Actual: " + donutOrder( 1 ) ); System.out.println( "Desired: " + ... ); System.out.println( "2 donuts:" ); System.out.println( "Actual: " + donutOrder( 2 ) ); System.out.println( "Desired: " + ... ); System.out.println( "10 donuts:" ); System.out.println( "Actual: " + donutOrder( 10 ) ); System.out.println( "Desired: " + ... ); System.out.println( "100 donuts:" ); System.out.println( "Actual: " + donutOrder(100 ) ); System.out.println( "Desired: " + 6175 ); // 6500¢ less 5% (325¢) System.out.println( "0 donuts:" ); System.out.println( "Actual: " + orderPrice( "donuts", 0 ) ); System.out.println( "Desired: " + ... ); System.out.println( "1 donut:" ); System.out.println( "Actual: " + orderPrice( "donuts", 1 ) ); System.out.println( "Desired: " + ... ); System.out.println( "2 donuts:" ); System.out.println( "Actual: " + orderPrice( "donuts", 2 ) ); System.out.println( "Desired: " + ... ); System.out.println( "10 donuts:" ); System.out.println( "Actual: " + orderPrice( "donuts", 10 ) ); System.out.println( "Desired: " + ... ); System.out.println( "100 donuts:" ); System.out.println( "Actual: " + orderPrice( "donuts", 100 ) ); System.out.println( "Desired: " + 6175 ); // 6500¢ less 5% (325¢) System.out.println( "0 fritters:" ); System.out.println( "Actual: " + orderPrice( "fritter", 0 ) ); System.out.println( "Desired: " + ... ); System.out.println( "1 fritter:" ); System.out.println( "Actual: " + orderPrice( "fritter", 1 ) ); System.out.println( "Desired: " + ... ); System.out.println( "2 fritters:" ); System.out.println( "Actual: " + orderPrice( "fritter", 2 ) ); System.out.println( "Desired: " + ... ); System.out.println( "4 fritters:" ); System.out.println( "Actual: " + orderPrice( "fritter", 4 ) ); System.out.println( "Desired: " + ... ); System.out.println( "100 fritters:" ); System.out.println( "Actual: " + orderPrice( "fritter", 100 ) ); System.out.println( "Desired: " + ... ); } } |
Still include the function
/** 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 ) { double basePrice; basePrice = numDonuts * 65; if (numDonuts >= 10) { double discountedPrice; discountedPrice = basePrice * (1 - 0.05); return doubleToInt( discountedPrice ); } else { return basePrice; } } |
Go ahead and add one more case:
1
Unfortunately, it's not even the case that
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
©2012, Ian Barland, Radford University Last modified 2012.Sep.13 (Thu) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |