RU beehive logo ITEC Department logo
ITEC 120
2007spring
ibarland,
jpittges

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

lect01c
a first program

Quickly recalling two of the expressions we typed in lab yesterday:

jo.pizzaArea(10) + jo.pizzaArea(2*6)
jo.pizzaArea( Math.sqrt(64) )
Remember the mantra for calling a method:
When calling a function: “object dot methodName openParen argument”
These two expressions further illustrate that the argument can be the result of a computation (2*6 or Math.sqrt(64)) and also that you can use the result of calling pizzaArea to do other stuff (like adding, in the first example).

Practice: Now it's your turn to write some functions.

The key feature to these programs is when we want to compute the area of (say) a 12″ pizza, we don't need to write 3.14*(12/2)*(12/2); we can write pizzaArea(12). What are the advantages of this approach?

This brings us to
The First Law of Programming: Do not repeat code, when you can re-use it.


1 For any numeric function, 0 and 1 are obvious inputs. consider:

There once was a girl from Purdue Whose limerick stopped at line two.
Or the more interesting test,
There once was a boy from Verdun
All good computer scientists also know there is a similar limerick about Nero, it goes without saying.      

2Can you spot the Pythagorean theorem at work, in jo.pizzaArea(12) + jo.pizzaArea(16) = jo.pizzaArea(20)?      

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2007, Ian Barland, Radford University
Last modified 2007.Aug.27 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme