main.m
#import <Foundation/Foundation.h>
#import "BNRForeignStockHolding.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
// Create BNRStockHoldings
BNRStockHolding *appl = [[BNRStockHolding alloc] init];
BNRStockHolding *msft = [[BNRStockHolding alloc] init];
BNRStockHolding *goog = [[BNRStockHolding alloc] init];
BNRForeignStockHolding *ssnlf = [[BNRForeignStockHolding alloc] init];
BNRForeignStockHolding *htc = [[BNRForeignStockHolding alloc] init];
// Set Stock Variables
[appl setPurchaseSharePrice: 60.0];
[appl setCurrentSharePrice: 99.3];
[appl setNumberOfShares: 10];
[appl setName: @"APPL"];
[msft setPurchaseSharePrice: 30.0];
[msft setCurrentSharePrice: 33.5];
[msft setNumberOfShares: 12];
[msft setName: @"MSFT"];
[goog setPurchaseSharePrice: 425.8];
[goog setCurrentSharePrice: 400.0];
[goog setNumberOfShares: 15];
[goog setName: @"GOOG"];
[ssnlf setPurchaseSharePrice: 1400.0];
[ssnlf setCurrentSharePrice: 1394.14];
[ssnlf setConversionRate: .34];
[ssnlf setNumberOfShares: 25];
[ssnlf setName: @"SSNLF"];
[htc setPurchaseSharePrice: 141.5];
[htc setCurrentSharePrice: 140.0];
[htc setNumberOfShares: 150];
[htc setConversionRate: .80];
[htc setName: @"HTC"];
// Create Stock Portfolio and add BNRStockHoldings
NSMutableArray *stockPortfolio = [[NSMutableArray alloc] init];
[stockPortfolio addObject: appl];
[stockPortfolio addObject: msft];
[stockPortfolio addObject: goog];
[stockPortfolio addObject: ssnlf];
[stockPortfolio addObject: htc];
for(BNRStockHolding *stock in stockPortfolio)
{
NSString *name = [stock name];
float purchasePrice = [stock purchaseSharePrice];
float currentPrice = [stock currentSharePrice];
int numberOfShares = [stock numberOfShares];
float cost = [stock costInDollars];
float currentValue = [stock valueInDollars];
NSLog(@"%@: ", name);
NSLog(@"Purchase price: $%.2f\n", purchasePrice);
NSLog(@"Current Price: $%.2f\n", currentPrice);
NSLog(@"Number of shares: %d\n", numberOfShares);
NSLog(@"Cost in dollars: $%.2f\n", cost);
NSLog(@"Current value: $%.2f\n\n", currentValue);
}
}
return 0;
}
BNRStockHolding.h
#import "BNRStockHolding.h"
@interface BNRForeignStockHolding : BNRStockHolding
@property (nonatomic) float conversionRate;
@end
BNRForeignStockHolding.h
#import "BNRForeignStockHolding.h"
@implementation BNRForeignStockHolding
- (float)costInDollars {
float purchaseSharePrice = [self purchaseSharePrice];
float conversionRate = [self conversionRate];
int numberOfShares = [self numberOfShares];
return purchaseSharePrice * conversionRate * numberOfShares;
}
- (float)valueInDollars {
float currentSharePrice = [self purchaseSharePrice];
float conversionRate = [self conversionRate];
int numberOfShares = [self numberOfShares];
return currentSharePrice * conversionRate * numberOfShares;
}
@end
Ok I don’t think I need to include foundation in main since it’s already included in BNRForeignStockHolding.h but I could be wrong… What is the standard for includes that are already included in your classes?