Hi All, First post so I apologize if I screw up the posting. I’ve gone through and written what I thought was a viable solution to the challenge but whenever I run it I get an uncaught exception error. Here’s the selections of my code:
BNRStockHolding.h
[code]#import <Foundation/Foundation.h>
@interface BNRStockHolding : NSObject
@property (nonatomic) float purchaseSharePrice;
@property (nonatomic) float currentSharePrice;
@property (nonatomic) int numberOfShares;
@property (nonatomic) char *companyName;
- (float)costInDollars; // purchaseSharePrice * numberOfShares
- (float)valueInDollars; // currentSharePrice * numberOfShares
@end
[/code]
BNRStockHolding.m
[code]#import “BNRStockHolding.h”
@implementation BNRStockHolding
-(float)costInDollars
{
return _purchaseSharePrice * _numberOfShares;
}
-(float)valueInDollars
{
return _currentSharePrice * _numberOfShares;
}
@end[/code]
BNRForeignStockHolding.h
[code]#import <Foundation/Foundation.h>
#import “BNRStockHolding.h”
@interface BNRForeignStockHolding : BNRStockHolding
{
float conversionRate;
}
@property (nonatomic) float conversionRate;
@end[/code]
BNRForeignStockHolding.m
[code]@implementation BNRForeignStockHolding
- (float) costInDollars
{
float costBeforeConversion = super.costInDollars;
return costBeforeConversion * conversionRate;
}
- (float) valueInDollars
{
float valueBeforeConversion = super.valueInDollars;
return valueBeforeConversion * conversionRate;
}
@end[/code]
And here’s main.m
[code]//
#import <Foundation/Foundation.h>
#import “BNRStockHolding.h”
#import “BNRForeignStockHolding.h”
int main(int argc, const char * argv[])
{
@autoreleasepool {
// Create three instances of BNRStockHolding
BNRStockHolding *firstHolding = [[BNRStockHolding alloc] init];
BNRStockHolding *secondHolding = [[BNRStockHolding alloc] init];
BNRStockHolding *thirdHolding = [[BNRStockHolding alloc] init];
// Set values for firstHolding
firstHolding.purchaseSharePrice = 2.30;
firstHolding.currentSharePrice = 4.50;
firstHolding.numberOfShares = 40;
firstHolding.companyName = "Google";
// Set values for secondHolding
secondHolding.purchaseSharePrice = 12.19;
secondHolding.currentSharePrice = 10.56;
secondHolding.numberOfShares = 90;
secondHolding.companyName = "Apple";
// Set values for thirdHolding
thirdHolding.purchaseSharePrice = 45.10;
thirdHolding.currentSharePrice = 49.51;
thirdHolding.numberOfShares = 210;
thirdHolding.companyName = "Microsoft";
// Create one instance of BNRForeignStockHolding
BNRForeignStockHolding *firstForeignHolding = [[BNRForeignStockHolding alloc] init];
// Set values for firstForeignHolding
firstForeignHolding.purchaseSharePrice = 2.30;
firstForeignHolding.currentSharePrice = 4.50;
firstForeignHolding.numberOfShares = 40;
firstForeignHolding.companyName = "Verstald LTD";
firstForeignHolding.conversionRate = 0.94;
// Create Mutable array then add the instances of BNRStockHolding
NSMutableArray *stockPortfolio = [NSMutableArray array];
[stockPortfolio addObject:firstHolding];
[stockPortfolio addObject:secondHolding];
[stockPortfolio addObject:thirdHolding];
[stockPortfolio addObject:firstForeignHolding];
// Calculate and Report their cost, value, and earnings
for (BNRStockHolding *sh in stockPortfolio) {
float cost = sh.costInDollars;
float value = sh.valueInDollars;
char *name = sh.companyName;
NSLog(@"Your %s stocks cost %.2f at time of purchase, are now worth %.2f.", name, cost, value);
for (BNRForeignStockHolding *fsh in stockPortfolio) {
float cost = fsh.costInDollars;
float value = fsh.valueInDollars;
float cRate = fsh.conversionRate;
char *name = fsh.companyName;
NSLog(@"Your %s stocks cost %.2f at time of purchase, are now worth %.2f at a rate of %.2f", name, cost, value, cRate);
}
}
}
return 0;
}[/code]
And here’s the error reciept I’m getting:
2014-02-15 19:55:21.979 Stocks[1172:303] Your Google stocks cost 92.00 at time of purchase, are now worth 180.00.
2014-02-15 19:55:22.001 Stocks[1172:303] -[BNRStockHolding conversionRate]: unrecognized selector sent to instance 0x100108fd0
2014-02-15 19:55:22.003 Stocks[1172:303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BNRStockHolding conversionRate]: unrecognized selector sent to instance 0x100108fd0'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff92bad41c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff98171e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff92bb02ed -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff92b0b5b2 ___forwarding___ + 1010
4 CoreFoundation 0x00007fff92b0b138 _CF_forwarding_prep_0 + 120
5 Stocks 0x000000010000173b main + 1835
6 libdyld.dylib 0x00007fff8ed085fd start + 1
7 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I’m really not sure whats going on here and any help would be much appreciated. I get that something is wrong with the conversionRate selector but I don’t get what or where to start with fixing it because compared to other solutions if found it looks like it should work. If anyone knows/sees anything and can even just point me in the direction of the problem or a fix I would be really grateful.