|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
double fizzle( String s ) |
1 /** Calculate the are of *crust* on a pizza, given its diameter. 2 * Krusteaze pizza has 3" of crust all the way around. 3 * @param diam The diameter of the pizza (in inches); must be 6 or more. 4 * @return The amount of crust (in square inches) 5 * p.crustArea( 6) = p.pizzaArea( 6) - p.toppingArea( 6) =~ 28.26 6 * p.crustArea(12) = p.pizzaArea(12) - p.toppingArea(12) =~ 84.78 7 * p.crustArea(20) = p.pizzaArea(20) - p.toppingArea(20) =~ 160.14 8 */ 9 double crustArea( double diam ) { 10 double totalArea; 11 totalArea = this.pizzaArea(diam); 12 13 double innerArea; 14 innerArea = this.toppingArea(diam); 15 16 return (totalArea - innerArea); 17 } |
Inside the class EmCee from lab, we'll have another function shorten, which takes in two inputs -- a last-name and a first-name, in that order -- and returns the person's initials. In addition, the function greetFriend takes the same inputs in the same order, and returns a greeting for that friend.
mcJo.shorten( "Rogers", "Fred" ) = "F.R." mcJo.greetFriend( "Rogers", "Fred" ) = "Yo, F.R. -- whazzup?" |
/** shorten: * Compute somebody's initials, given their last and first name. * @param * @param * @return * * Test cases (presuming that mcJo is an instance of EmCee): * mcJo.shorten( , ) = * mcJo.shorten( , ) = */ shorten( , ) { return "Z.Z."; // A dummy stub. } |
Submit this same .html file to WebCT.
Alternately, you can submit your java file
(since that contains all the javadoc used to generate the html page):
H:/itec120/hw02/EmCee.java
If you submit this
“.java”
file, you don't have to submit the .html file,
although there's nothing wrong with submitting both.
Note that Windows Explorer hides the “.java”
suffix. Do not submit files with other suffixes
(no “.class”
or
“.ctxt”
files).
optional: You probably saw that your test cases all run together, in the auto-generated documentation. You can fix this by writing “<br/>” at the end of each line of your test-cases. (“<br/>” is HTML markup for a line-break.)
String s1; s1 = "hello"; s1.substring(0,1) String s2; s2 = "bye"; s2.substring(0,1) String s3; s3 = "Z"; s3.substring(0,1) String tooShort; tooShort = ""; tooShort.substring(0,1) // ERROR! |
1Remember that while “local variable” and “parameter” are very similar concepts, they are technically different from each other. ↩
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2007, Ian Barland, Radford University Last modified 2007.Sep.21 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |