/**
* A PizzaServer knows how to answer basic
* questions about the area of pizzas.
* Also, this version adds a salary.
*
* @author Ian Barland
* @version 2007.Feb.05
*/
class PizzaServer {
/** The salary of this particular PizzaServer (in $/hr). */
double salary = 5.15;
/** The bank balance of this particular PizzaServer (in $). */
double balance = 0.0;
/** Ask this particular PizzaServer about their salary.
* @return This PizzaServer's salary (in $/hr).
*/
double getSalary() {
return this.salary;
}
/** Set this particular PizzaServer's salary.
* @param newSalary The new salary for this employee (in $/hr).
*/
void setSalary( double newSalary ) {
this.salary = newSalary;
}
/** Ask this particular PizzaServer about their balance.
* @return This PizzaServer's balance (in $).
*/
double getBalance() {
return this.balance;
}
/** Set this particular PizzaServer's balance.
* @param newSalary The new balance for this employee (in $).
*/
void setBalance( double newBalance ) {
this.balance = newBalance;
}
/**
* 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:
*
pizzaArea( 0) = 0
*
pizzaArea( 2) =~ 3.14
*
pizzaArea(20) =~ 314.0
*
*
pizzaArea( 4) =~ 12.52
*
pizzaArea(16) =~ 201.5ish
*/
double pizzaArea( double diam ) {
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( 6) = pizzaArea( 6) - 0 =~ 28.16
*
crustArea(20) = pizzaArea(20) - pizzaArea(14) =~ 314 - 153.86 = 160.14ish
*/
double crustArea( double diam ) {
return pizzaArea(diam) - pizzaArea( diam - 2*3 );
}
}