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 BeanShell

Date:06/18/05
Author:Tom Edelson
URL:http://www.well.com/user/edelsont/
Comments:2
Info:http://www.beanshell.org/
Score: (3.33 in 3 votes)
// 99bottles.bsh
//
// Tom Edelson, last modified 2005-06-18

// This is BeanShell, a scripting language based on, and implemented in,
// Java.
//
// Mostly, the BeanShell language just is Java; but type declarations
// on variables are optional, and some scripting-friendly features
// have been added.  One of these features is the ability of a method
// to return a "closure", which is a bundle of [persistent] data and
// code; thus, like an object, but not derived from a class.
//
// In this example, each of the methods "newWall" and "newSinger" creates and
// returns a closure, whose content is defined by statements,
// and nested method definitions, within the "constructor" itself.

// For more information on BeanShell, and to download it, visit
//
//    http://www.beanshell.org/


formatBottleCount (number) {

    if (number == 0) {
        return "No bottles ";
    }

    if (number == 1) {
        return "One bottle ";
    }

    return number + " bottles ";

} // end method formatBottleCount


newWall (initialCount) {

    count = initialCount;

    getCount () {
        return count;
    }

    hasBottles () {
        return count > 0;
    }

    takeOne () {
        count--;
        return count;
    }

    return this;

} // end method newWall


newSinger (wallRef) {

    wall = wallRef;
    count = wall.getCount();
    countString = formatBottleCount (count);
    print ("");

    singVerse () {

        print (countString + "of beer on the wall,");
        print (countString + "of beer;");

        count = wall.takeOne();
        print ("Take one down, pass it around,");

        countString = formatBottleCount (count);
        print (countString + "of beer on the wall.");
        print ("");
 
    } // end method singVerse

    finish () {
        print ("Gotta be another beer wall around here somewhere ...");
        print ("");
    }

    return this;

} // end method newSinger


// Main program code:

wall = newWall (99);

singer = newSinger (wall);

while (wall.hasBottles()) {
    singer.singVerse();
}

singer.finish();


// end of file "99bottles.bsh".

Download Source | Write Comment

Alternative Versions

Comments

>>  LUCYjS said on 02/07/10 04:02:52

LUCYjS I think it's charismatic, because it exhibit a very academic-focussed attitude. Preserving the honesty of the academic system seems to be a greatest importance, although directly enjoin refunded ads for such a service seems a forceless response. When the firm is known by your friends who were animated with the results of the alliance, about this good topic . But don't foreget always to use <a href="http://www.plagiarismsearch.com">plagiarism checker</a> run them through this plagiarism detection system for absolute checking and make sure that your material is authentic.

>>  cosplay said on 06/09/10 08:42:47

cosplay <a href="http://www.topjewelry1.com">top jewelry </a>
<a href="http://www.efashionblog.org">fashion blog</a>
<a href="http://www.lifeofworld.com">life world</a>
<a href="http://www.choosehandbag.com">choose handbag</a>
<a href="http://www.tiffanyking.com">Tiffany Jewellery</a>
<a href="http://www.infashionlife.com">fashion life</a>
<a href="http://manoloblahniksale.com">manoloblahnik sale</a>
<a href="http://www.xmasgiftsale.com/gift/" >xmas gift</a>
<a href="http://www.ckloo.com">Ckloo</a>
<a href="http://www.tiffanyworld.org"> jewellery</a>
<a href="http://www.buydress.org/">dresses </a>
<a href="http://www.ishoesblog.com/">shoes blog</a>
<a href="http://www.tiffanyfree.org/">jewellery</a>
<a href="http://www.edhardyfor.com/">ed hardy blog </a>
<a href="http://ourweddingsales.com">wedding sale</a>

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: