Challenge Solution with helpful extras


#1

Included extra properties such as stockSymbol, companyName. Also, created a method that NSLogs the values of each object.

main.m

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


int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        BNRStockHolding *stockTXRH = [[BNRStockHolding alloc]init];
        BNRStockHolding *stockGSAT = [[BNRStockHolding alloc]init];
        BNRStockHolding *stockAAPL = [[BNRStockHolding alloc]init];
        NSMutableArray *stockArray = [[NSMutableArray alloc]init];
         
 /*******************************************************************/
 
        stockTXRH.companyName = (@"Texas Roadhouse");
        stockTXRH.stockSymbol = "TXRH";
        stockTXRH.purchaseSharePrice = 26.62;
        stockTXRH.currentSharePrice = 28.31;
        stockTXRH.numberOfShares = 2556;
        [stockArray addObject:stockTXRH];
        
/*******************************************************************/
        
        stockGSAT.companyName = (@"GlobalStar");
        stockGSAT.stockSymbol = "GSAT";
        stockGSAT.purchaseSharePrice = 1.00;
        stockGSAT.currentSharePrice = 3.11;
        stockGSAT.numberOfShares = 1200;
        [stockArray addObject:stockGSAT];
        
        
/*******************************************************************/
        
        stockAAPL.companyName = (@"Apple");
        stockAAPL.stockSymbol = "AAPL";
        stockAAPL.purchaseSharePrice = 10.50;
        stockAAPL.currentSharePrice = 99.62;
        stockAAPL.numberOfShares = 500;
        [stockArray addObject:stockAAPL];
        
/*******************************************************************/
        
    for (BNRStockHolding *s in stockArray)
    {
        // Custom method that NSLogs the values.  See BNRStockHolding.m
        [s getDescription:s];
        
    }
        
       
    }
 return 0;
}

BNRStockHolding.h

#import <Foundation/Foundation.h>

@interface BNRStockHolding : NSObject

@property (nonatomic) NSString *companyName;
@property (nonatomic) char *stockSymbol;
@property (nonatomic) float purchaseSharePrice;
@property (nonatomic) float currentSharePrice;
@property (nonatomic) int   numberOfShares;


- (float) costInDollars; // purchaseSharePrice * numberOfShares
- (float) valueInDollars; // currentSharePrice * numberOfShares
- (void) getDescription:(BNRStockHolding *) s;

@end

BNRStockHolding.m


#import "BNRStockHolding.h"

@implementation BNRStockHolding

              
- (float) costInDollars
{
 
    return self.purchaseSharePrice * self.numberOfShares;

}
              
- (float) valueInDollars
{
    return self.currentSharePrice * self.numberOfShares;
}

- (void) getDescription:(BNRStockHolding *) s
{
    NSLog(@"\n\n      Company Name: %@\n      Stock Symbol: %s\n  Number of Shares: %d\nPurchase Share Price: %.2f\n Current Share Price: %.2f\n     Cost In Dollars: %.2f\n    Value in Dollars: %.2f\n",
          self.companyName, self.stockSymbol, self.numberOfShares,
          self.purchaseSharePrice, self.currentSharePrice, [self costInDollars],
          [self valueInDollars]);

}

@end