鳳鳴は祖父の俳号

日記 メモ そんなの

Dart言語で99 bottles of beer

 Dart言語で手探りながら99 bottles of beerを書いた。

Dart programming language | Dart

99 Bottles of Beer | Start

class Bottle {
  var b1 = 'bottle' ;
  var b2 = 'bottles' ;

  number(n) {
    return (n==1)? b1 : b2 ;
  }
}


class BoB {

  number(n,lq) {
    var bottle = new Bottle() ;
    int nn = n - 1 ;
    String bn = bottle.number(n) ;
    String bnn = bottle.number(nn) ;
    switch(n) {
    case 0:
      print('No more $bn of $lq on the wall, no more $bn of $lq.') ;
      break ;
    case 1:
      print('1 $bn of $lq on the wall, 1 $bn of $lq.');
      break ;
    default:
      print('$n $bn of $lq on the wall, $n $bn of $lq.');
      print('Take one down and pass it around, $nn $bnn of $lq on the wall.');
    }
  }
}


main() {
  var bob = new BoB() ;
  for (int b = 99; b >= 0; b--) {
    bob.number(b,'beer');
  }
}