RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

lab10b
finishing your beverage

Overloading: Two functions with the same name, but with different signatures. Note that when looking at a function call, it's possible to discern which function you want, based on the different signature. Fore example: java.lang.String#substring vs. java.lang.String#substring.

We can overload functions ourselves: we can write String oneVerse(int n) that returns verse #n about rootbeer, and String oneVerse(int n, String bev) that returns verse #n about bev. Whenever somebody calls oneVerse, the computer knows which version it should call based on what arguments are being supplied.

We will complete last week's lab10a—practicing loops: 99 bottles, and check you off (through #8) — that's six functions, but four of them will be a single line, and one more will be a loop with only two lines in the body. The only long one is printing a single verse!

Be sure not to have lots of repeated code! In particular:


1 A more challenging task would be eliminating some of the words that are repeated within a single verse — e.g. changing “on the wall” to “off the shelf” is more reasonable to require two changes. However, you certainly are able (and welcome) to make that updatable-with-only-one-change.      

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2012, Ian Barland, Radford University
Last modified 2012.Nov.01 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme