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 Decaf

Date:08/11/05
Author:Timothy Chen
URL:n/a
Comments:0
Info:http://www.stanford.edu/class/cs143/handouts/14-Decaf-Specification.pdf
Score: (2.75 in 4 votes)
class Wall {
  Bottle[] bottlesOnWall;
  
  void InitWall() {
    int i;	

    bottlesOnWall = NewArray (100, Bottle);
    for (i = 1; i <= 99; i = i + 1) {
      bottlesOnWall[i] = New (Bottle);
      bottlesOnWall[i].SetNumberOnWall(i);
    }
    bottlesOnWall[0] = New(NoBottle);
  }

  Bottle[] GetBottlesOnWall() {
    return bottlesOnWall;
  }
}

class Bottle {
  int numberOnWall;

  void SetNumberOnWall(int number) {
    numberOnWall = number;
  }
  
  int GetNumberOnWall() {
     return numberOnWall;
  }
}

class NoBottle extends Bottle {
  void SetNumberOnWall() {}

  int GetNumberOnWall() {
    return 0;
  }
}

  


void main() {
  Wall myWall;
  int i;
	
  myWall = New (Wall);
  myWall.InitWall();
  for (i = (myWall.GetBottlesOnWall()).length() - 1; i >= 0; i = i - 1) {  
    if ((myWall.GetBottlesOnWall())[i].GetNumberOnWall() == 0) {
      Print ("No more bottle of beer on the wall, ");
      Print ("no more bottles of beer.\n");
      Print ("Go to the store and buy some more, ");
      Print ("99 bottles of beer on the wall.\n");
    } else {
	Print ((myWall.GetBottlesOnWall())[i].GetNumberOnWall(), " bottles of beer on the wall, ");
	Print ((myWall.GetBottlesOnWall())[i].GetNumberOnWall(), " bottles of beer.\n");
	Print ("Take one down and pass it around, ");
	Print ((myWall.GetBottlesOnWall())[i].GetNumberOnWall() - 1, " bottles of beer on the wall.\n\n");
    }
  }
}

Download Source | Write Comment

Alternative Versions

Comments

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: