|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
For today's lab, you must work with a partner. We will check off your work, before leaving.
/** 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. * * If 'p' is a PizzaServer instance, then: * p.pizzaArea( 0) = 0 +/- 0.001 * p.pizzaArea( 2) = 3.14 +/- 0.001 * p.pizzaArea(12) = 113.04 +/- 0.001 * p.pizzaArea(16) = 200.96 +/- 0.001 * p.pizzaArea(20) = 314 +/- 0.001 */ double pizzaArea( double diam ) { return 3.14 * (diam/2) * (diam/2); } } |
Krusteaze Pizza Korp. has an all-you-can-eat buffet meal. In order to encourage people to bring their friends, the price is $8 for the first person, plus $4.50 for each friend after that.
Write a function buffetPrice,
which is given the size of the group (1 or bigger),
and returns the total cost.
(Your function will be used by the cash register.)
We'll follow the usual series of steps:
/* test cases for buffetPrice, assuming 'zoe' is some existing PizzaServer: * zoe.buffetPrice( ____ ) = ______ * zoe.buffetPrice( ____ ) = ______ * zoe.buffetPrice( ____ ) = ______ */ |
What will the first line of code look like, for this function? First, let's recall how the first line of pizzaArea and ufoHeightAt each looked, from Tuesday's lab:
int ufoHeightAt( int frameNum ) { ... } double pizzaArea( double diam ) { ... } |
This information called the function's signature.
Some customers are concerned with the surface area of their pizza. Others ignore the crusts, and want to ask the server how much topping-area each pizza comes with. The server happens to know that Krusteaze Pizzas have a 3″ border of crust all the way around them (what cheapskates!).
Write the function toppingArea.
One last problem (not needed for check-off, but you should
be able to work through it):
Some people actually like the crust of a pizza!
They want to ask PizzaServers how
much crust there is, on a pizza of a given size!
Follow the same steps above, to write crustArea. (In my solution, the only arithmetic inside crustArea is a single subtraction.)
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2008, Ian Barland, Radford University Last modified 2008.Jan.31 (Thu) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |