/** * class PizzaServer, version 3. * * A PizzaServer knows how to answer basic * questions about the area of pizzas. * Also, this version adds a salary, and uses javadoc comments. * * @author Ian Barland * @version 3, having added a salary field. */ class PizzaServer { /** The width of crust all the way around the edge of a pizza. */ final double CRUST_WIDTH = 2.0; /** Minimum wage, in $/hr. (Should be defined in some other class, gov.deptOfLabor ?) */ final double MINIMUM_WAGE = 5.15; /** The salary of this particular PizzaServer (in $/hr). */ double salary = MINIMUM_WAGE; /** Ask this particular PizzaServer about their salary. * @return This PizzaServer's salary (in $/hr). */ double getSalary() { return salary; } /** * Set this particular PizzaServer's salary. * @param newSalary The new salary for this employee (in $/hr). */ void setSalary( double newSalary ) { salary = newSalary; } /** * Calculate the area of a pizza, given its diameter. * @param diam The diameter of a pizza (in inches). * @return The area (in sq.in.). *
*
Test cases: *
pieArea( 0) = 0 *
pieArea( 2) =~ 3.14 *
pieArea(20) =~ 314.0 * *
pieArea( 4) =~ 12.52 *
pieArea(16) =~ 201.5ish */ double pieArea( double diam ) { final double radius = diam/2.0; return Math.PI * radius * radius; } /** * Given a pizza diameter, calculate how much crust there is (in sq.in.). * It is guaranteed that there is {@value CRUST_WIDTH}" of crust around the edge; * hey, this means 2*{@value CRUST_WIDTH}" is the smallest allowable pizza. * @param diam The diameter of the pizza (in inches); diam must be >= 4. * @return The amount of crust (in sq.in.). *
*
Test cases: *
crustArea( 4) = pieArea( 4) =~ 12.52 *
crustArea(20) = pieArea(20) - pieArea(16) =~ 314 - 201.5ish = 112.5ish */ double crustArea( double diam ) { return pieArea(diam) - pieArea( diam - 2*CRUST_WIDTH ); } }