Challenge 18.01 from Russia


**BNRStockHolding.h**

#import <Foundation/Foundation.h>

@interface BNRStockHolding : NSObject
{
    NSString *_nameOfCompany;
    float _purchasedSharePrice;
    float _currentSharePrice;
    int _numberOfShares;
}

- (NSString *)nameOfCompany;
- (void)setNameOfCompany:(NSString *)name;
- (float)purchasedSharePrice;
- (void)setPurchasedSharePrice:(float)p;
- (float)currentSharePrice;
- (void)setCurrentSharePrice:(float)c;
- (int)numberOfShares;
- (void)setNumberOfShares:(int)n;

- (float)costInDollars;  // purchaseSharePrice * numberOfShares
- (float)valueInDollars;    // currentSharePrice * numberfShares

@end

**BNRStockHolding.m**

#import "BNRStockHolding.h"

@implementation BNRStockHolding

- (NSString *) nameOfCompany
{
    return _nameOfCompany;
}

-(void) setNameOfCompany:(NSString *)name
{
    _nameOfCompany = [name uppercaseString];
}

- (float)purchasedSharePrice
{
    return _purchasedSharePrice;
}

-(void)setPurchasedSharePrice:(float)p
{
    _purchasedSharePrice = p;
}

- (float)currentSharePrice
{
    return _currentSharePrice;
}

- (void)setCurrentSharePrice:(float)c
{
    _currentSharePrice = c;
}

- (int)numberOfShares
{
    return _numberOfShares;
}

- (void)setNumberOfShares:(int)n
{
    _numberOfShares = n;
}

- (float)costInDollars
{
    float p = [self purchasedSharePrice];
    int n = [self numberOfShares];
    return p * n;
}

- (float)valueInDollars
{
    float c = [self currentSharePrice];
    int n = [self numberOfShares];
    return c * n;
}
@end

**main.m**

#import <Foundation/Foundation.h>
#import "BNRStockHolding.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        // Create an empty mutable array
        NSMutableArray *array = [[NSMutableArray alloc] init];
        
        // Create three instance BNRStockHolding
        BNRStockHolding *s1 = [[BNRStockHolding alloc] init];
        BNRStockHolding *s2 = [[BNRStockHolding alloc] init];
        BNRStockHolding *s3 = [[BNRStockHolding alloc] init];
        
        // Setting values for instances
        [s1 setNameOfCompany:@"AEROFLOT"];
        [s1 setPurchasedSharePrice:2.30];
        [s1 setCurrentSharePrice:4.50];
        [s1 setNumberOfShares:40];
        
        [s2 setNameOfCompany:@"ALROSA"];
        [s2 setPurchasedSharePrice:12.19];
        [s2 setCurrentSharePrice:10.56];
        [s2 setNumberOfShares:90];
        
        [s3 setNameOfCompany:@"GAZPROM"];
        [s3 setPurchasedSharePrice:45.10];
        [s3 setCurrentSharePrice:49.51];
        [s3 setNumberOfShares:210];
        
        // Filling an array with instancies
        [array addObject:s1];
        [array addObject:s2];
        [array addObject:s3];
        
        for (BNRStockHolding *share in array) {
            NSLog(@"Company \"%@\". Price for one share is %.2f$. Total value in dollars %.2f$\n", [share nameOfCompany], [share costInDollars], [share valueInDollars]);
        }
    }
    return 0;
}