Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Ferite

(Objects)

Date:09/25/06
Author:Rowan Lewis
URL:http://pixelcarnage.net/
Comments:1
Info:http://ferite.org/
Score: (3.00 in 4 votes)
class BottlesOfBeerSong {
	private number bottles;
	private string output;
	private string format;
	
	constructor(number bottles) {
		self(bottles, "html");
	}
	
	constructor(number bottles, string format) {
		.bottles = bottles;
		.format = format;
	}
	
	function play() {
		while (.bottles > 0) {
			string bottles = "bottle";
			
			.start();
			
			if (.bottles > 1) {
				bottles += "s";
			}
			
			.line("${.bottles} ${bottles} of beer on the wall,");
			.line("${.bottles} ${bottles} of beer,");
			.line("Take one down, pass it around,");
			
			.bottles--;
			
			if (.bottles > 0) {
				.line("${.bottles} ${bottles} of beer on the wall.");
			} else {
				.line("No bottles of beer on the wall!");
			}
			
			.stop();
		}
		
		return .output;
	}
	
	private function start() {
		if (.format == "html") {
			.output += "\n<p>";
		}
	}
	
	private function line(string line) {
		if (.format == "html") {
			.output += "\n\t${line}<br />";
		} else {
			.output += "\n${line}";
		}
	}
	
	private function stop() {
		if (.format == "html") {
			.output = .output[..-7] + "\n</p>";
		}
	}
	
}

object song = new BottlesOfBeerSong(99);
Console.println("" + song.play());

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Using closures.Rowan Lewis09/25/062

Comments

>>  HannahBuchanan24 said on 07/10/10 04:35:00

HannahBuchanan24 Various people in every country take the <a href="http://bestfinance-blog.com/topics/personal-loans">personal loans</a> in different creditors, because it's comfortable.

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!

Name:

eMail:

URL:

Security Code:
  
Comment: