Sha256: fc6a383e6b2ab67d9fa80d7671fa1150b4a73524ed0e5ab08cc28292586b28e7

Contents?: true

Size: 1.87 KB

Versions: 268

Compression:

Stored size: 1.87 KB

Contents

#import "BeerSongExample.h"

@interface BeerSongExample ()

@property(nonatomic,assign) int numberOfBeerBottles;

@end

@implementation BeerSongExample

-(instancetype)initWithNumberOfBeerBottles:(int)numberOfBottles{
    self = [super init];
    
    if(self){
        
        self.numberOfBeerBottles = numberOfBottles;
    }
    
    return self;
}

-(NSString*)singBeerSong{
    
    int numberOfBottles = self.numberOfBeerBottles;
    NSMutableString *verses = [NSMutableString string];
    while (numberOfBottles > 2) {
        
        [verses appendFormat:@"%d bottles of beer on the wall, %d bottles of beer.\n",numberOfBottles,numberOfBottles];
        numberOfBottles--;
        [verses appendFormat:@"Take one down and pass it around, %d bottles of beer on the wall.\n\n",numberOfBottles];
    }
    
    while(numberOfBottles <= 2){
        
        switch (numberOfBottles) { //!OCLint
                
            case 2: [verses appendFormat:@"%d bottles of beer on the wall, %d bottles of beer.\n",numberOfBottles,numberOfBottles];
                numberOfBottles--;
                [verses appendFormat:@"Take one down and pass it around, %d bottle of beer on the wall.\n\n",numberOfBottles];
                break;
                
            case 1:[verses appendFormat:@"%d bottle of beer on the wall, %d bottle of beer.\n",numberOfBottles,numberOfBottles];
                numberOfBottles--;
                [verses appendString:@"Take one down and pass it around, no more bottles of beer on the wall.\n\n"];
                break;
                
            case 0: [verses appendString:@"No more bottles of beer on the wall, no more bottles of beer.\n"];
                numberOfBottles+=99;
                [verses appendFormat:@"Go to the store and buy some more, %d bottles of beer on the wall.",numberOfBottles];
                break;
        }
    }
    
    return verses;
}
@end

Version data entries

268 entries across 268 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.179 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.178 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.177 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.176 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.175 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.174 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.173 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.172 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.171 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.170 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.169 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.167 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.166 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.165 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.164 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.163 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.162 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.161 tracks/objective-c/exercises/beer-song/BeerSongExample.m
trackler-2.2.1.160 tracks/objective-c/exercises/beer-song/BeerSongExample.m