/** Functions to calculate the area of pizza purchased, given a diameter. * * @author Ian Barland * @version 2007.Jan.10 */ class PizzaServer { /** Calculate the area of a pizza, given its diameter. * @param diam The diameter of the pizza, in inches. * @return The area of the pizza, in square inches. * p.pizzaArea( 0) = 0 * p.pizzaArea( 2) =~ 3.14 * p.pizzaArea(12) =~ 113.04 * p.pizzaArea(16) =~ 209.96 * p.pizzaArea(20) =~ 314 */ double pizzaArea( double diam ) { double radius; radius = diam/2; return 3.14 * radius * radius; } /** Calculate the are of *topping* on a pizza, given its diameter. * Krusteaze pizza has 3" of crust all the way around. * @param diam The diameter of the pizza (in inches); must be 6 or more. * @return The amount of topping (in square inches) * p.toppingArea( 6) = p.pizzaArea( 6 - 2*3 ) = 0 * p.toppingArea( 8) = p.pizzaArea( 8 - 2*3 ) =~ 3.14 * p.toppingArea(12) = p.pizzaArea( 12 - 2*3 ) =~ 28.26 */ double toppingArea( double diam ) { double innerDiam; innerDiam = diam - 2*3; /* We subtract the part of the diameter which is crust: 3" on each side. */ return this.pizzaArea( innerDiam ); } /** Calculate the are of *crust* on a pizza, given its diameter. * Krusteaze pizza has 3" of crust all the way around. * @param diam The diameter of the pizza (in inches); must be 6 or more. * @return The amount of crust (in square inches) * p.crustArea( 6) = p.pizzaArea( 6) - p.toppingArea( 6) =~ 28.26 * p.crustArea(12) = p.pizzaArea(12) - p.toppingArea(12) =~ 84.78 * p.crustArea(20) = p.pizzaArea(20) - p.toppingArea(20) =~ 160.14 */ double crustArea( double diam ) { double totalArea; totalArea = this.pizzaArea(diam); double innerArea; innerArea = this.toppingArea(diam); return (totalArea - innerArea); } /** Calculate the area of pizza ordered, given its diameter, * based on the "free foot friday" promo of itec120-lect01c. * @param diam The diameter of the pizza ordered, in inches. * @return The total area of pizza received, in square inches. * p.friPizzaArea( 0) = p.pizzaArea( 0) + pizzaArea(12) =~ 113.04 * p.friPizzaArea( 2) = p.pizzaArea( 2) + pizzaArea(12) =~ 116.18 * p.friPizzaArea(12) = p.pizzaArea(12) + pizzaArea(12) =~ 226.08 * p.friPizzaArea(20) = p.pizzaArea(20) + pizzaArea(12) =~ 427.04 */ double friPizzaArea( double diam ) { return this.pizzaArea(diam) + this.pizzaArea(12); } }