Language Dart
(Class used version)
Date: | 10/12/11 |
Author: | Jimin Park |
URL: | n/a |
Comments: | 0 |
Info: | http://www.dartlang.org/ |
Score: | (2.70 in 10 votes) |
class Bottle{ int _amount; String _kind,_place; get amount() => _amount; set amount(int amt){ if(amt<0){ _amount = 99; throw "Go to store and buy some more, ${toStr(true)}."; } if(amt>99) throw "I'm drunk."; _amount = amt; } get place() => _place; set place(String plc){ _place = plc; } get kind() => _kind; set kind(String knd){ _kind = knd; } Bottle(amt,knd,plc){ amount = amt; kind = knd; place = plc; } String toStr(bool long){ String plural = amount==1?'':'s'; String append = long?" on $place":''; if(amount>0) return "$amount bottle$plural of $kind$append"; else return "No bottles of $kind$append"; } } main(){ Bottle beer = new Bottle(99,'beer','the wall'); print("${beer.toStr(true)}, ${beer.toStr(false)}."); while(beer.amount-->0){ print("Take one down and pass it around, ${beer.toStr(true)}."); print("${beer.toStr(true)}, ${beer.toStr(false)}."); } }
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
1 | houmei | 10/13/11 | 0 | |
An object oriented version of the song. | Ville Saalo | 10/15/11 | 0 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments