Better way to declare conversionRate value


#1

Hi all, I have created the subclass ForeignStockHolding and over-written the method calls, but believe there has to be a better way to set the value for conversionRate than what I have done below. My way might as well be hard-coded - which doesnt make any sense. Can someone recommend a better place to set the value? Thx

From BNRForeignStockHolding.m

#import "BNRForeignStockHolding.h"
@implementation BNRForeignStockHolding

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

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

@end

#2

Pass it as an argument to the init method:

- (instancetype)initWithConversionRate:(double)rate
{
    self = [super init];
    if (self) {
         _conversionRate = rate;
          ...
    }
    return self;
}

- (instancetype)init
{
    return [self initWithConversionRate:1.0];  // 1.0 is a reasonable default
}

#3

Per the challenge you should be passing the conversion rate as an element of the BNRForeignStockHolding held in the array. Just like you are setting the current share price or the number of shares, you should also set the conversion rate as part of the overall stock instance. For example from main.m:

        [fHolding2 setPurchaseSharePrice:12.19];
        [fHolding2 setCurrentSharePrice:10.56];
        [fHolding2 setNumberOfShares:90];
        [fHolding2 setConversionRate:0.50];