/** Functions to calculate the area of pizza purchased, given a diameter. * * @author Ian Barland */ class Pizzeria extends Object120 { static double pizzaArea( double diam ) { double r; r = diam/2; return Math.PI * r * r; } /** The amount of crust (in sq. in) on a pizza of the given diameter. * Our pizzeria uses 3" crust, all the way around. * @param d the diameter of the pizza. Must be >= 6. * @return The amount of crust (in sq. in) on a pizza of diameter `d`. */ static double crustArea_v1( double d ) { double totalArea; totalArea = Math.PI * d/2 * d/2; double toppingArea; toppingArea = Math.PI * (d-6)/2 * (d-6)/2 ; return totalArea - toppingArea ; } static double crustArea( double d ) { return (Math.PI * d/2 * d/2) - (Math.PI * (d-6)/2 * (d-6)/2); } static double crustArea_v3( double d ) { return pizzaArea(d) - pizzaArea(d-6); } static double crustArea_v4( double d ) { double totalArea; totalArea = pizzaArea(d); double toppingArea; toppingArea = pizzaArea(d-6); return totalArea - toppingArea ; } static void testPizzeria() { System.out.println( "The area of a 20-inch pizza:" ); System.out.println( "Actual: " + pizzaArea(20) ); System.out.println( "Expect: 314 (approx)" ); System.out.println( "" ); System.out.println( "The area of a 0-inch pizza:" ); System.out.println( "Actual: " + pizzaArea(0) ); System.out.println( "Expect: 0" ); System.out.println( "" ); System.out.println( "The area of a 2-inch pizza:" ); System.out.println( "Actual: " + pizzaArea(2) ); System.out.println( "Expect: 3.14 (approx)" ); System.out.println( "" ); System.out.println( "The crust on a 6-inch pizza:" ); System.out.println( "Actual: " + crustArea(6) ); System.out.println( "Expect: 28.27 (approx)" ); System.out.println( "" ); System.out.println( "The crust on a 26-inch pizza:" ); System.out.println( "Actual: " + crustArea(26) ); System.out.println( "Expect: 216.8 (approx)" ); System.out.println( "" ); System.out.println( "The crust on a 14-inch pizza:" ); System.out.println( "Actual: " + crustArea(14) ); System.out.println( "Expect: 103.67\"sq (approx)" ); System.out.println( "" ); System.out.println( "Buffet price for 1 person:" ); System.out.println( "Actual answer: " + buffetPrice(1) ); System.out.println( "Expect answer: 8.00" ); System.out.println( "Buffet price for 2 people:" ); System.out.println( "Actual answer: " + buffetPrice(2) ); System.out.println( "Expect answer: 12.50" ); System.out.println( "Buffet price for 11 people:" ); System.out.println( "Actual answer: " + buffetPrice(11) ); System.out.println( "Expect answer: 53.00" ); System.out.println( "========" ); } static double buffetPrice( int numCusts ) { return 8 + (numCusts-1)*4.5; } }