# Solution to Challenge by Roggy67

#1

Hear is my solution for the chapter 19 challenge.
All comments, questions, or suggestions are welcome, and once again thanks to all those who have helped me see the light.

main.m

``````#import <Foundation/Foundation.h>
#import "StockHolding.h"
#import "ForeignStockHolding.h"
#import "Portfolio.h"

// generate random float between 0 and 10 not inclusive      Im really not 100% sure of this inclusivity
#define randomFloat()   random() % 1000 / (float) 100.0

// generate random int between 1 and 100 inclusive
#define randomInt()     (random() % 100) + 1

int main(int argc, const char * argv[])
{

@autoreleasepool {
Portfolio *portfolio = [[Portfolio alloc] init];

// generate domestic stocks
unsigned int numberOfStocks = randomInt();
NSLog(@"\n\n\nNumber of Domestic stocks in portfolio = %d\n\n", numberOfStocks);

for (unsigned int i = 0; i < numberOfStocks; i++) {
StockHolding *stock = [[StockHolding alloc] init];
[stock setNumberOfShare:randomInt()];
[stock setPurchaseSharePrice:randomInt() * randomFloat()];
[stock setCurrentSharePrice:randomInt() * randomFloat()];

NSLog(@"stock NumberOfShare = %d", [stock numberOfShare]);
NSLog(@"stock PurchaseSharePrice = %f", [stock purchaseSharePrice]);
NSLog(@"stock CurrentSharePrice = %f\n\n", [stock currentSharePrice]);

}

// generate foreign stocks
numberOfStocks = randomInt();
NSLog(@"\n\n\nNumber of Foreign stocks in portfolio = %d\n\n", numberOfStocks);

for (unsigned int i = 0; i < numberOfStocks; i++) {
ForeignStockHolding *stock = [[ForeignStockHolding alloc] init];
[stock setNumberOfShare:randomInt()];
[stock setPurchaseSharePrice:randomInt() * randomFloat()];
[stock setCurrentSharePrice:randomInt() * randomFloat()];
// Only Foreign stocks have a conversion selector
[stock setConversionRate:randomFloat()];

NSLog(@"stock NumberOfShare = %d", [stock numberOfShare]);
NSLog(@"stock PurchaseSharePrice = %f", [stock purchaseSharePrice]);
NSLog(@"stock CurrentSharePrice = %f", [stock currentSharePrice]);
// Only Foreign stocks have a conversion selector
NSLog(@"stock Conversion rate = %f\n\n", [stock conversionRate]);

}

NSLog(@"\n\nthe portfolio has a value of \$%f\n\n", [portfolio currentValue]);
}
return 0;
}
``````

Portfolio.h

``````#import <Foundation/Foundation.h>
@class ForeignStockHolding;
@class StockHolding;

@interface Portfolio : NSObject
{
NSMutableArray *foreignStocks;
NSMutableArray *domesticStocks;
}

- (float)currentValue;                                  // returns the total value of a portfolio instance

@end``````

Portfolio.m

``````#import "Portfolio.h"
#import "ForeignStockHolding.h"
#import "StockHolding.h"

@implementation Portfolio

{
if (!foreignStocks) {
foreignStocks = [[NSMutableArray alloc] init];
}
}

{
if (!domesticStocks) {
domesticStocks = [[NSMutableArray alloc] init];
}
}

- (float)currentValue
{
float tally = 0.0;
for (int i = 0; i < [foreignStocks count]; i++) {
tally += [[foreignStocks objectAtIndex:i] valueInDollarsF];
}
for (int i = 0; i < [domesticStocks count]; i++) {
tally += [[domesticStocks objectAtIndex:i] valueInDollars];
}
return tally;
}

@end``````

StockHolding.h

``````#import <Foundation/Foundation.h>

@interface StockHolding : NSObject
{
float purchaseSharePrice;
float currentSharePrice;
int numberOfShare;
}

@property float purchaseSharePrice;
@property float currentSharePrice;
@property int numberOfShare;

- (float)costInDollars;  // purchaseSharePrice * numberOfShare
- (float)valueInDollars; // currentSharePrice * numberOfShare

@end``````

StockHolding.m

``````#import "StockHolding.h"

@implementation StockHolding

@synthesize purchaseSharePrice, currentSharePrice, numberOfShare;

- (float)costInDollars
{
return [self purchaseSharePrice] * [self numberOfShare];
}
- (float)valueInDollars
{
return [self currentSharePrice] * [self numberOfShare];
}

@end``````

ForeignStockHolding.h

``````#import <Foundation/Foundation.h>
#import "StockHolding.h"

@interface ForeignStockHolding : StockHolding
{
float conversionRate;
}

@property float conversionRate;

- (float)costInDollars;
- (float)valueInDollarsF;

@end``````

ForeignStockHolding.m

``````#import "ForeignStockHolding.h"

@implementation ForeignStockHolding

@synthesize conversionRate;

- (float)costInDollars
{
return [super costInDollars] * [self conversionRate];
}
- (float)valueInDollarsF
{
return [super valueInDollars] * [self conversionRate];
}

@end``````

My Output

[code]2012-10-26 12:12:32.901 Stocks[905:403]

Number of Domestic stocks in portfolio = 84

2012-10-26 12:12:32.903 Stocks[905:403] stock NumberOfShare = 87
2012-10-26 12:12:32.903 Stocks[905:403] stock PurchaseSharePrice = 86.150002
2012-10-26 12:12:32.904 Stocks[905:403] stock CurrentSharePrice = 96.349998

2012-10-26 12:12:32.904 Stocks[905:403] stock NumberOfShare = 87
2012-10-26 12:12:32.905 Stocks[905:403] stock PurchaseSharePrice = 98.489998
2012-10-26 12:12:32.906 Stocks[905:403] stock CurrentSharePrice = 24.619999

2012-10-26 12:12:32.906 Stocks[905:403] stock NumberOfShare = 28
2012-10-26 12:12:32.907 Stocks[905:403] stock PurchaseSharePrice = 90.589996
2012-10-26 12:12:32.907 Stocks[905:403] stock CurrentSharePrice = 72.260002

2012-10-26 12:12:32.907 Stocks[905:403] stock NumberOfShare = 41
2012-10-26 12:12:32.908 Stocks[905:403] stock PurchaseSharePrice = 27.719999
2012-10-26 12:12:32.908 Stocks[905:403] stock CurrentSharePrice = 38.110001

2012-10-26 12:12:32.909 Stocks[905:403] stock NumberOfShare = 69
2012-10-26 12:12:32.909 Stocks[905:403] stock PurchaseSharePrice = 71.290001
2012-10-26 12:12:32.910 Stocks[905:403] stock CurrentSharePrice = 87.300003

2012-10-26 12:12:32.914 Stocks[905:403] stock NumberOfShare = 63
2012-10-26 12:12:32.914 Stocks[905:403] stock PurchaseSharePrice = 23.670000
2012-10-26 12:12:32.915 Stocks[905:403] stock CurrentSharePrice = 44.290001

2012-10-26 12:12:32.916 Stocks[905:403] stock NumberOfShare = 3
2012-10-26 12:12:32.916 Stocks[905:403] stock PurchaseSharePrice = 22.580000
2012-10-26 12:12:32.917 Stocks[905:403] stock CurrentSharePrice = 70.669998

2012-10-26 12:12:32.917 Stocks[905:403] stock NumberOfShare = 94
2012-10-26 12:12:32.918 Stocks[905:403] stock PurchaseSharePrice = 56.110001
2012-10-26 12:12:32.918 Stocks[905:403] stock CurrentSharePrice = 44.290001

2012-10-26 12:12:32.919 Stocks[905:403] stock NumberOfShare = 74
2012-10-26 12:12:32.919 Stocks[905:403] stock PurchaseSharePrice = 30.189999
2012-10-26 12:12:32.920 Stocks[905:403] stock CurrentSharePrice = 89.370003

2012-10-26 12:12:32.920 Stocks[905:403] stock NumberOfShare = 99
2012-10-26 12:12:32.921 Stocks[905:403] stock PurchaseSharePrice = 27.150000
2012-10-26 12:12:32.937 Stocks[905:403] stock CurrentSharePrice = 74.129997

2012-10-26 12:12:32.937 Stocks[905:403] stock NumberOfShare = 27
2012-10-26 12:12:32.938 Stocks[905:403] stock PurchaseSharePrice = 100.800003
2012-10-26 12:12:32.938 Stocks[905:403] stock CurrentSharePrice = 64.729996

2012-10-26 12:12:32.939 Stocks[905:403] stock NumberOfShare = 63
2012-10-26 12:12:32.939 Stocks[905:403] stock PurchaseSharePrice = 79.959999
2012-10-26 12:12:32.940 Stocks[905:403] stock CurrentSharePrice = 84.050003

2012-10-26 12:12:32.941 Stocks[905:403] stock NumberOfShare = 26
2012-10-26 12:12:32.941 Stocks[905:403] stock PurchaseSharePrice = 87.269997
2012-10-26 12:12:32.942 Stocks[905:403] stock CurrentSharePrice = 41.049999

2012-10-26 12:12:32.942 Stocks[905:403] stock NumberOfShare = 47
2012-10-26 12:12:32.943 Stocks[905:403] stock PurchaseSharePrice = 32.130001
2012-10-26 12:12:32.943 Stocks[905:403] stock CurrentSharePrice = 58.240002

2012-10-26 12:12:32.944 Stocks[905:403] stock NumberOfShare = 96
2012-10-26 12:12:32.944 Stocks[905:403] stock PurchaseSharePrice = 87.449997
2012-10-26 12:12:32.945 Stocks[905:403] stock CurrentSharePrice = 17.670000

2012-10-26 12:12:32.945 Stocks[905:403] stock NumberOfShare = 35
2012-10-26 12:12:32.946 Stocks[905:403] stock PurchaseSharePrice = 64.430000
2012-10-26 12:12:32.946 Stocks[905:403] stock CurrentSharePrice = 50.869999

2012-10-26 12:12:32.947 Stocks[905:403] stock NumberOfShare = 9
2012-10-26 12:12:32.947 Stocks[905:403] stock PurchaseSharePrice = 77.779999
2012-10-26 12:12:32.948 Stocks[905:403] stock CurrentSharePrice = 93.839996

2012-10-26 12:12:32.949 Stocks[905:403] stock NumberOfShare = 4
2012-10-26 12:12:32.949 Stocks[905:403] stock PurchaseSharePrice = 58.540001
2012-10-26 12:12:32.950 Stocks[905:403] stock CurrentSharePrice = 108.320000

2012-10-26 12:12:32.950 Stocks[905:403] stock NumberOfShare = 61
2012-10-26 12:12:32.951 Stocks[905:403] stock PurchaseSharePrice = 79.680000
2012-10-26 12:12:32.951 Stocks[905:403] stock CurrentSharePrice = 39.119999

2012-10-26 12:12:32.952 Stocks[905:403] stock NumberOfShare = 27
2012-10-26 12:12:32.953 Stocks[905:403] stock PurchaseSharePrice = 86.940002
2012-10-26 12:12:32.953 Stocks[905:403] stock CurrentSharePrice = 46.950001

2012-10-26 12:12:32.954 Stocks[905:403] stock NumberOfShare = 71
2012-10-26 12:12:32.954 Stocks[905:403] stock PurchaseSharePrice = 37.779999
2012-10-26 12:12:32.955 Stocks[905:403] stock CurrentSharePrice = 73.010002

2012-10-26 12:12:32.955 Stocks[905:403] stock NumberOfShare = 98
2012-10-26 12:12:32.956 Stocks[905:403] stock PurchaseSharePrice = 5.170000
2012-10-26 12:12:32.956 Stocks[905:403] stock CurrentSharePrice = 98.519997

2012-10-26 12:12:32.957 Stocks[905:403] stock NumberOfShare = 57
2012-10-26 12:12:32.957 Stocks[905:403] stock PurchaseSharePrice = 3.800000
2012-10-26 12:12:32.958 Stocks[905:403] stock CurrentSharePrice = 90.410004

2012-10-26 12:12:32.958 Stocks[905:403] stock NumberOfShare = 66
2012-10-26 12:12:32.959 Stocks[905:403] stock PurchaseSharePrice = 93.440002
2012-10-26 12:12:32.960 Stocks[905:403] stock CurrentSharePrice = 23.400000

2012-10-26 12:12:32.960 Stocks[905:403] stock NumberOfShare = 30
2012-10-26 12:12:32.961 Stocks[905:403] stock PurchaseSharePrice = 32.169998
2012-10-26 12:12:32.961 Stocks[905:403] stock CurrentSharePrice = 104.709999

2012-10-26 12:12:32.962 Stocks[905:403] stock NumberOfShare = 82
2012-10-26 12:12:32.962 Stocks[905:403] stock PurchaseSharePrice = 82.089996
2012-10-26 12:12:32.963 Stocks[905:403] stock CurrentSharePrice = 32.669998

2012-10-26 12:12:32.963 Stocks[905:403] stock NumberOfShare = 57
2012-10-26 12:12:32.964 Stocks[905:403] stock PurchaseSharePrice = 100.529999
2012-10-26 12:12:32.964 Stocks[905:403] stock CurrentSharePrice = 95.650002

2012-10-26 12:12:32.965 Stocks[905:403] stock NumberOfShare = 7
2012-10-26 12:12:32.965 Stocks[905:403] stock PurchaseSharePrice = 85.190002
2012-10-26 12:12:32.966 Stocks[905:403] stock CurrentSharePrice = 29.280001

2012-10-26 12:12:32.966 Stocks[905:403] stock NumberOfShare = 72
2012-10-26 12:12:32.967 Stocks[905:403] stock PurchaseSharePrice = 40.290001
2012-10-26 12:12:32.967 Stocks[905:403] stock CurrentSharePrice = 3.190000

2012-10-26 12:12:32.968 Stocks[905:403] stock NumberOfShare = 71
2012-10-26 12:12:32.969 Stocks[905:403] stock PurchaseSharePrice = 75.080002
2012-10-26 12:12:32.969 Stocks[905:403] stock CurrentSharePrice = 18.400000

2012-10-26 12:12:32.970 Stocks[905:403] stock NumberOfShare = 50
2012-10-26 12:12:32.970 Stocks[905:403] stock PurchaseSharePrice = 103.230003
2012-10-26 12:12:32.971 Stocks[905:403] stock CurrentSharePrice = 20.450001

2012-10-26 12:12:32.999 Stocks[905:403] stock NumberOfShare = 47
2012-10-26 12:12:33.001 Stocks[905:403] stock PurchaseSharePrice = 60.209999
2012-10-26 12:12:33.001 Stocks[905:403] stock CurrentSharePrice = 58.790001

2012-10-26 12:12:33.002 Stocks[905:403] stock NumberOfShare = 89
2012-10-26 12:12:33.003 Stocks[905:403] stock PurchaseSharePrice = 66.279999
2012-10-26 12:12:33.003 Stocks[905:403] stock CurrentSharePrice = 44.500000

2012-10-26 12:12:33.004 Stocks[905:403] stock NumberOfShare = 94
2012-10-26 12:12:33.004 Stocks[905:403] stock PurchaseSharePrice = 0.340000
2012-10-26 12:12:33.005 Stocks[905:403] stock CurrentSharePrice = 65.239998

2012-10-26 12:12:33.005 Stocks[905:403] stock NumberOfShare = 15
2012-10-26 12:12:33.006 Stocks[905:403] stock PurchaseSharePrice = 95.559998
2012-10-26 12:12:33.006 Stocks[905:403] stock CurrentSharePrice = 47.910000

2012-10-26 12:12:33.007 Stocks[905:403] stock NumberOfShare = 28
2012-10-26 12:12:33.007 Stocks[905:403] stock PurchaseSharePrice = 73.589996
2012-10-26 12:12:33.017 Stocks[905:403] stock CurrentSharePrice = 40.320000

2012-10-26 12:12:33.018 Stocks[905:403] stock NumberOfShare = 52
2012-10-26 12:12:33.018 Stocks[905:403] stock PurchaseSharePrice = 39.279999
2012-10-26 12:12:33.019 Stocks[905:403] stock CurrentSharePrice = 79.070000

2012-10-26 12:12:33.020 Stocks[905:403] stock NumberOfShare = 75
2012-10-26 12:12:33.020 Stocks[905:403] stock PurchaseSharePrice = 29.580000
2012-10-26 12:12:33.021 Stocks[905:403] stock CurrentSharePrice = 95.290001

2012-10-26 12:12:33.021 Stocks[905:403] stock NumberOfShare = 38
2012-10-26 12:12:33.022 Stocks[905:403] stock PurchaseSharePrice = 42.930000
2012-10-26 12:12:33.023 Stocks[905:403] stock CurrentSharePrice = 22.280001

2012-10-26 12:12:33.023 Stocks[905:403] stock NumberOfShare = 44
2012-10-26 12:12:33.024 Stocks[905:403] stock PurchaseSharePrice = 20.279999
2012-10-26 12:12:33.024 Stocks[905:403] stock CurrentSharePrice = 36.760002

2012-10-26 12:12:33.025 Stocks[905:403] stock NumberOfShare = 5
2012-10-26 12:12:33.025 Stocks[905:403] stock PurchaseSharePrice = 50.630001
2012-10-26 12:12:33.026 Stocks[905:403] stock CurrentSharePrice = 18.380001

2012-10-26 12:12:33.026 Stocks[905:403] stock NumberOfShare = 7
2012-10-26 12:12:33.027 Stocks[905:403] stock PurchaseSharePrice = 49.040001
2012-10-26 12:12:33.027 Stocks[905:403] stock CurrentSharePrice = 19.280001

2012-10-26 12:12:33.028 Stocks[905:403] stock NumberOfShare = 89
2012-10-26 12:12:33.028 Stocks[905:403] stock PurchaseSharePrice = 78.169998
2012-10-26 12:12:33.029 Stocks[905:403] stock CurrentSharePrice = 26.959999

2012-10-26 12:12:33.030 Stocks[905:403] stock NumberOfShare = 25
2012-10-26 12:12:33.030 Stocks[905:403] stock PurchaseSharePrice = 47.700001
2012-10-26 12:12:33.031 Stocks[905:403] stock CurrentSharePrice = 87.900002

2012-10-26 12:12:33.031 Stocks[905:403] stock NumberOfShare = 100
2012-10-26 12:12:33.032 Stocks[905:403] stock PurchaseSharePrice = 79.250000
2012-10-26 12:12:33.032 Stocks[905:403] stock CurrentSharePrice = 49.900002

2012-10-26 12:12:33.033 Stocks[905:403] stock NumberOfShare = 6
2012-10-26 12:12:33.033 Stocks[905:403] stock PurchaseSharePrice = 48.540001
2012-10-26 12:12:33.034 Stocks[905:403] stock CurrentSharePrice = 92.690002

2012-10-26 12:12:33.035 Stocks[905:403] stock NumberOfShare = 83
2012-10-26 12:12:33.035 Stocks[905:403] stock PurchaseSharePrice = 46.639999
2012-10-26 12:12:33.036 Stocks[905:403] stock CurrentSharePrice = 102.070000

2012-10-26 12:12:33.036 Stocks[905:403] stock NumberOfShare = 56
2012-10-26 12:12:33.037 Stocks[905:403] stock PurchaseSharePrice = 7.480000
2012-10-26 12:12:33.037 Stocks[905:403] stock CurrentSharePrice = 17.219999

2012-10-26 12:12:33.038 Stocks[905:403] stock NumberOfShare = 29
2012-10-26 12:12:33.038 Stocks[905:403] stock PurchaseSharePrice = 102.430000
2012-10-26 12:12:33.039 Stocks[905:403] stock CurrentSharePrice = 51.680000

2012-10-26 12:12:33.039 Stocks[905:403] stock NumberOfShare = 41
2012-10-26 12:12:33.040 Stocks[905:403] stock PurchaseSharePrice = 25.110001
2012-10-26 12:12:33.040 Stocks[905:403] stock CurrentSharePrice = 16.049999

2012-10-26 12:12:33.041 Stocks[905:403] stock NumberOfShare = 2
2012-10-26 12:12:33.042 Stocks[905:403] stock PurchaseSharePrice = 68.300003
2012-10-26 12:12:33.042 Stocks[905:403] stock CurrentSharePrice = 81.050003

2012-10-26 12:12:33.043 Stocks[905:403] stock NumberOfShare = 21
2012-10-26 12:12:33.043 Stocks[905:403] stock PurchaseSharePrice = 40.439999
2012-10-26 12:12:33.044 Stocks[905:403] stock CurrentSharePrice = 31.219999

2012-10-26 12:12:33.044 Stocks[905:403] stock NumberOfShare = 66
2012-10-26 12:12:33.045 Stocks[905:403] stock PurchaseSharePrice = 12.160000
2012-10-26 12:12:33.045 Stocks[905:403] stock CurrentSharePrice = 84.580002

2012-10-26 12:12:33.046 Stocks[905:403] stock NumberOfShare = 25
2012-10-26 12:12:33.046 Stocks[905:403] stock PurchaseSharePrice = 37.619999
2012-10-26 12:12:33.047 Stocks[905:403] stock CurrentSharePrice = 30.000000

2012-10-26 12:12:33.047 Stocks[905:403] stock NumberOfShare = 37
2012-10-26 12:12:33.048 Stocks[905:403] stock PurchaseSharePrice = 60.989998
2012-10-26 12:12:33.049 Stocks[905:403] stock CurrentSharePrice = 84.500000

2012-10-26 12:12:33.049 Stocks[905:403] stock NumberOfShare = 69
2012-10-26 12:12:33.050 Stocks[905:403] stock PurchaseSharePrice = 80.729996
2012-10-26 12:12:33.050 Stocks[905:403] stock CurrentSharePrice = 39.810001

2012-10-26 12:12:33.051 Stocks[905:403] stock NumberOfShare = 31
2012-10-26 12:12:33.051 Stocks[905:403] stock PurchaseSharePrice = 41.939999
2012-10-26 12:12:33.052 Stocks[905:403] stock CurrentSharePrice = 61.630001

2012-10-26 12:12:33.052 Stocks[905:403] stock NumberOfShare = 100
2012-10-26 12:12:33.053 Stocks[905:403] stock PurchaseSharePrice = 89.989998
2012-10-26 12:12:33.053 Stocks[905:403] stock CurrentSharePrice = 105.589996

2012-10-26 12:12:33.058 Stocks[905:403] stock NumberOfShare = 74
2012-10-26 12:12:33.059 Stocks[905:403] stock PurchaseSharePrice = 19.680000
2012-10-26 12:12:33.059 Stocks[905:403] stock CurrentSharePrice = 90.949997

2012-10-26 12:12:33.060 Stocks[905:403] stock NumberOfShare = 27
2012-10-26 12:12:33.060 Stocks[905:403] stock PurchaseSharePrice = 66.839996
2012-10-26 12:12:33.061 Stocks[905:403] stock CurrentSharePrice = 40.900002

2012-10-26 12:12:33.062 Stocks[905:403] stock NumberOfShare = 85
2012-10-26 12:12:33.062 Stocks[905:403] stock PurchaseSharePrice = 81.419998
2012-10-26 12:12:33.063 Stocks[905:403] stock CurrentSharePrice = 37.070000

2012-10-26 12:12:33.063 Stocks[905:403] stock NumberOfShare = 46
2012-10-26 12:12:33.064 Stocks[905:403] stock PurchaseSharePrice = 57.790001
2012-10-26 12:12:33.064 Stocks[905:403] stock CurrentSharePrice = 26.869999

2012-10-26 12:12:33.065 Stocks[905:403] stock NumberOfShare = 13
2012-10-26 12:12:33.065 Stocks[905:403] stock PurchaseSharePrice = 49.720001
2012-10-26 12:12:33.066 Stocks[905:403] stock CurrentSharePrice = 59.090000

2012-10-26 12:12:33.067 Stocks[905:403] stock NumberOfShare = 37
2012-10-26 12:12:33.067 Stocks[905:403] stock PurchaseSharePrice = 13.420000
2012-10-26 12:12:33.068 Stocks[905:403] stock CurrentSharePrice = 89.059998

2012-10-26 12:12:33.068 Stocks[905:403] stock NumberOfShare = 2
2012-10-26 12:12:33.069 Stocks[905:403] stock PurchaseSharePrice = 16.719999
2012-10-26 12:12:33.069 Stocks[905:403] stock CurrentSharePrice = 23.549999

2012-10-26 12:12:33.070 Stocks[905:403] stock NumberOfShare = 20
2012-10-26 12:12:33.070 Stocks[905:403] stock PurchaseSharePrice = 106.209999
2012-10-26 12:12:33.071 Stocks[905:403] stock CurrentSharePrice = 13.390000

2012-10-26 12:12:33.071 Stocks[905:403] stock NumberOfShare = 12
2012-10-26 12:12:33.072 Stocks[905:403] stock PurchaseSharePrice = 46.669998
2012-10-26 12:12:33.072 Stocks[905:403] stock CurrentSharePrice = 7.280000

2012-10-26 12:12:33.073 Stocks[905:403] stock NumberOfShare = 28
2012-10-26 12:12:33.073 Stocks[905:403] stock PurchaseSharePrice = 59.840000
2012-10-26 12:12:33.074 Stocks[905:403] stock CurrentSharePrice = 67.199997

2012-10-26 12:12:33.074 Stocks[905:403] stock NumberOfShare = 25
2012-10-26 12:12:33.075 Stocks[905:403] stock PurchaseSharePrice = 24.690001
2012-10-26 12:12:33.089 Stocks[905:403] stock CurrentSharePrice = 96.809998

2012-10-26 12:12:33.089 Stocks[905:403] stock NumberOfShare = 31
2012-10-26 12:12:33.090 Stocks[905:403] stock PurchaseSharePrice = 86.919998
2012-10-26 12:12:33.090 Stocks[905:403] stock CurrentSharePrice = 78.720001

2012-10-26 12:12:33.091 Stocks[905:403] stock NumberOfShare = 51
2012-10-26 12:12:33.091 Stocks[905:403] stock PurchaseSharePrice = 28.850000
2012-10-26 12:12:33.092 Stocks[905:403] stock CurrentSharePrice = 24.990000

2012-10-26 12:12:33.093 Stocks[905:403] stock NumberOfShare = 41
2012-10-26 12:12:33.093 Stocks[905:403] stock PurchaseSharePrice = 50.980000
2012-10-26 12:12:33.094 Stocks[905:403] stock CurrentSharePrice = 15.980000

2012-10-26 12:12:33.094 Stocks[905:403] stock NumberOfShare = 91
2012-10-26 12:12:33.095 Stocks[905:403] stock PurchaseSharePrice = 29.900000
2012-10-26 12:12:33.095 Stocks[905:403] stock CurrentSharePrice = 14.809999

2012-10-26 12:12:33.096 Stocks[905:403] stock NumberOfShare = 20
2012-10-26 12:12:33.096 Stocks[905:403] stock PurchaseSharePrice = 43.320000
2012-10-26 12:12:33.097 Stocks[905:403] stock CurrentSharePrice = 64.940002

2012-10-26 12:12:33.097 Stocks[905:403] stock NumberOfShare = 5
2012-10-26 12:12:33.098 Stocks[905:403] stock PurchaseSharePrice = 86.690002
2012-10-26 12:12:33.098 Stocks[905:403] stock CurrentSharePrice = 80.760002

2012-10-26 12:12:33.099 Stocks[905:403] stock NumberOfShare = 51
2012-10-26 12:12:33.100 Stocks[905:403] stock PurchaseSharePrice = 63.599998
2012-10-26 12:12:33.100 Stocks[905:403] stock CurrentSharePrice = 47.790001

2012-10-26 12:12:33.101 Stocks[905:403] stock NumberOfShare = 85
2012-10-26 12:12:33.101 Stocks[905:403] stock PurchaseSharePrice = 95.050003
2012-10-26 12:12:33.103 Stocks[905:403] stock CurrentSharePrice = 26.670000

2012-10-26 12:12:33.103 Stocks[905:403] stock NumberOfShare = 5
2012-10-26 12:12:33.104 Stocks[905:403] stock PurchaseSharePrice = 22.610001
2012-10-26 12:12:33.105 Stocks[905:403] stock CurrentSharePrice = 57.259998

2012-10-26 12:12:33.105 Stocks[905:403] stock NumberOfShare = 60
2012-10-26 12:12:33.106 Stocks[905:403] stock PurchaseSharePrice = 46.020000
2012-10-26 12:12:33.107 Stocks[905:403] stock CurrentSharePrice = 7.060000

2012-10-26 12:12:33.108 Stocks[905:403] stock NumberOfShare = 85
2012-10-26 12:12:33.109 Stocks[905:403] stock PurchaseSharePrice = 29.420000
2012-10-26 12:12:33.109 Stocks[905:403] stock CurrentSharePrice = 73.279999

2012-10-26 12:12:33.110 Stocks[905:403] stock NumberOfShare = 90
2012-10-26 12:12:33.111 Stocks[905:403] stock PurchaseSharePrice = 81.080002
2012-10-26 12:12:33.111 Stocks[905:403] stock CurrentSharePrice = 62.980000

2012-10-26 12:12:33.112 Stocks[905:403] stock NumberOfShare = 37
2012-10-26 12:12:33.113 Stocks[905:403] stock PurchaseSharePrice = 15.530001
2012-10-26 12:12:33.114 Stocks[905:403] stock CurrentSharePrice = 51.029999

2012-10-26 12:12:33.114 Stocks[905:403] stock NumberOfShare = 34
2012-10-26 12:12:33.115 Stocks[905:403] stock PurchaseSharePrice = 39.480000
2012-10-26 12:12:33.115 Stocks[905:403] stock CurrentSharePrice = 97.540001

2012-10-26 12:12:33.116 Stocks[905:403] stock NumberOfShare = 68
2012-10-26 12:12:33.116 Stocks[905:403] stock PurchaseSharePrice = 49.680000
2012-10-26 12:12:33.117 Stocks[905:403] stock CurrentSharePrice = 34.000000

2012-10-26 12:12:33.122 Stocks[905:403]

Number of Foreign stocks in portfolio = 47

2012-10-26 12:12:33.122 Stocks[905:403] stock NumberOfShare = 89
2012-10-26 12:12:33.123 Stocks[905:403] stock PurchaseSharePrice = 99.489998
2012-10-26 12:12:33.124 Stocks[905:403] stock CurrentSharePrice = 93.029999
2012-10-26 12:12:33.124 Stocks[905:403] stock Conversion rate = 0.330000

2012-10-26 12:12:33.125 Stocks[905:403] stock NumberOfShare = 64
2012-10-26 12:12:33.125 Stocks[905:403] stock PurchaseSharePrice = 99.529999
2012-10-26 12:12:33.126 Stocks[905:403] stock CurrentSharePrice = 98.860001
2012-10-26 12:12:33.126 Stocks[905:403] stock Conversion rate = 1.250000

2012-10-26 12:12:33.127 Stocks[905:403] stock NumberOfShare = 53
2012-10-26 12:12:33.127 Stocks[905:403] stock PurchaseSharePrice = 105.750000
2012-10-26 12:12:33.128 Stocks[905:403] stock CurrentSharePrice = 89.570000
2012-10-26 12:12:33.128 Stocks[905:403] stock Conversion rate = 7.290000

2012-10-26 12:12:33.129 Stocks[905:403] stock NumberOfShare = 37
2012-10-26 12:12:33.129 Stocks[905:403] stock PurchaseSharePrice = 64.139999
2012-10-26 12:12:33.130 Stocks[905:403] stock CurrentSharePrice = 25.600000
2012-10-26 12:12:33.131 Stocks[905:403] stock Conversion rate = 3.040000

2012-10-26 12:12:33.132 Stocks[905:403] stock NumberOfShare = 29
2012-10-26 12:12:33.132 Stocks[905:403] stock PurchaseSharePrice = 27.500000
2012-10-26 12:12:33.133 Stocks[905:403] stock CurrentSharePrice = 53.560001
2012-10-26 12:12:33.133 Stocks[905:403] stock Conversion rate = 9.020000

2012-10-26 12:12:33.134 Stocks[905:403] stock NumberOfShare = 95
2012-10-26 12:12:33.134 Stocks[905:403] stock PurchaseSharePrice = 103.989998
2012-10-26 12:12:33.135 Stocks[905:403] stock CurrentSharePrice = 43.389999
2012-10-26 12:12:33.136 Stocks[905:403] stock Conversion rate = 0.020000

2012-10-26 12:12:33.136 Stocks[905:403] stock NumberOfShare = 29
2012-10-26 12:12:33.137 Stocks[905:403] stock PurchaseSharePrice = 8.000000
2012-10-26 12:12:33.137 Stocks[905:403] stock CurrentSharePrice = 87.470001
2012-10-26 12:12:33.138 Stocks[905:403] stock Conversion rate = 5.380000

2012-10-26 12:12:33.138 Stocks[905:403] stock NumberOfShare = 60
2012-10-26 12:12:33.139 Stocks[905:403] stock PurchaseSharePrice = 56.349998
2012-10-26 12:12:33.139 Stocks[905:403] stock CurrentSharePrice = 37.389999
2012-10-26 12:12:33.140 Stocks[905:403] stock Conversion rate = 6.920000

2012-10-26 12:12:33.141 Stocks[905:403] stock NumberOfShare = 16
2012-10-26 12:12:33.141 Stocks[905:403] stock PurchaseSharePrice = 32.040001
2012-10-26 12:12:33.142 Stocks[905:403] stock CurrentSharePrice = 29.490000
2012-10-26 12:12:33.142 Stocks[905:403] stock Conversion rate = 9.640000

2012-10-26 12:12:33.143 Stocks[905:403] stock NumberOfShare = 86
2012-10-26 12:12:33.143 Stocks[905:403] stock PurchaseSharePrice = 32.430000
2012-10-26 12:12:33.144 Stocks[905:403] stock CurrentSharePrice = 36.770000
2012-10-26 12:12:33.144 Stocks[905:403] stock Conversion rate = 9.000000

2012-10-26 12:12:33.144 Stocks[905:403] stock NumberOfShare = 39
2012-10-26 12:12:33.145 Stocks[905:403] stock PurchaseSharePrice = 80.489998
2012-10-26 12:12:33.146 Stocks[905:403] stock CurrentSharePrice = 92.669998
2012-10-26 12:12:33.157 Stocks[905:403] stock Conversion rate = 9.880000

2012-10-26 12:12:33.158 Stocks[905:403] stock NumberOfShare = 93
2012-10-26 12:12:33.159 Stocks[905:403] stock PurchaseSharePrice = 102.430000
2012-10-26 12:12:33.160 Stocks[905:403] stock CurrentSharePrice = 52.290001
2012-10-26 12:12:33.160 Stocks[905:403] stock Conversion rate = 3.900000

2012-10-26 12:12:33.161 Stocks[905:403] stock NumberOfShare = 83
2012-10-26 12:12:33.161 Stocks[905:403] stock PurchaseSharePrice = 45.410000
2012-10-26 12:12:33.162 Stocks[905:403] stock CurrentSharePrice = 77.260002
2012-10-26 12:12:33.162 Stocks[905:403] stock Conversion rate = 2.320000

2012-10-26 12:12:33.162 Stocks[905:403] stock NumberOfShare = 62
2012-10-26 12:12:33.163 Stocks[905:403] stock PurchaseSharePrice = 45.599998
2012-10-26 12:12:33.163 Stocks[905:403] stock CurrentSharePrice = 17.230000
2012-10-26 12:12:33.164 Stocks[905:403] stock Conversion rate = 7.610000

2012-10-26 12:12:33.164 Stocks[905:403] stock NumberOfShare = 82
2012-10-26 12:12:33.165 Stocks[905:403] stock PurchaseSharePrice = 10.900000
2012-10-26 12:12:33.165 Stocks[905:403] stock CurrentSharePrice = 34.959999
2012-10-26 12:12:33.169 Stocks[905:403] stock Conversion rate = 3.670000

2012-10-26 12:12:33.170 Stocks[905:403] stock NumberOfShare = 78
2012-10-26 12:12:33.170 Stocks[905:403] stock PurchaseSharePrice = 40.900002
2012-10-26 12:12:33.171 Stocks[905:403] stock CurrentSharePrice = 31.240000
2012-10-26 12:12:33.172 Stocks[905:403] stock Conversion rate = 0.570000

2012-10-26 12:12:33.172 Stocks[905:403] stock NumberOfShare = 15
2012-10-26 12:12:33.173 Stocks[905:403] stock PurchaseSharePrice = 70.050003
2012-10-26 12:12:33.173 Stocks[905:403] stock CurrentSharePrice = 61.119999
2012-10-26 12:12:33.174 Stocks[905:403] stock Conversion rate = 3.860000

2012-10-26 12:12:33.174 Stocks[905:403] stock NumberOfShare = 1
2012-10-26 12:12:33.175 Stocks[905:403] stock PurchaseSharePrice = 53.260002
2012-10-26 12:12:33.175 Stocks[905:403] stock CurrentSharePrice = 103.160004
2012-10-26 12:12:33.176 Stocks[905:403] stock Conversion rate = 5.520000

2012-10-26 12:12:33.176 Stocks[905:403] stock NumberOfShare = 79
2012-10-26 12:12:33.177 Stocks[905:403] stock PurchaseSharePrice = 38.459999
2012-10-26 12:12:33.177 Stocks[905:403] stock CurrentSharePrice = 96.470001
2012-10-26 12:12:33.178 Stocks[905:403] stock Conversion rate = 9.700000

2012-10-26 12:12:33.178 Stocks[905:403] stock NumberOfShare = 52
2012-10-26 12:12:33.179 Stocks[905:403] stock PurchaseSharePrice = 86.309998
2012-10-26 12:12:33.188 Stocks[905:403] stock CurrentSharePrice = 101.570000
2012-10-26 12:12:33.189 Stocks[905:403] stock Conversion rate = 6.270000

2012-10-26 12:12:33.189 Stocks[905:403] stock NumberOfShare = 13
2012-10-26 12:12:33.190 Stocks[905:403] stock PurchaseSharePrice = 88.139999
2012-10-26 12:12:33.190 Stocks[905:403] stock CurrentSharePrice = 60.119999
2012-10-26 12:12:33.191 Stocks[905:403] stock Conversion rate = 0.900000

2012-10-26 12:12:33.191 Stocks[905:403] stock NumberOfShare = 13
2012-10-26 12:12:33.192 Stocks[905:403] stock PurchaseSharePrice = 85.099998
2012-10-26 12:12:33.192 Stocks[905:403] stock CurrentSharePrice = 70.889999
2012-10-26 12:12:33.193 Stocks[905:403] stock Conversion rate = 2.740000

2012-10-26 12:12:33.193 Stocks[905:403] stock NumberOfShare = 56
2012-10-26 12:12:33.194 Stocks[905:403] stock PurchaseSharePrice = 47.200001
2012-10-26 12:12:33.194 Stocks[905:403] stock CurrentSharePrice = 42.869999
2012-10-26 12:12:33.195 Stocks[905:403] stock Conversion rate = 8.880000

2012-10-26 12:12:33.195 Stocks[905:403] stock NumberOfShare = 39
2012-10-26 12:12:33.196 Stocks[905:403] stock PurchaseSharePrice = 73.699997
2012-10-26 12:12:33.196 Stocks[905:403] stock CurrentSharePrice = 92.559998
2012-10-26 12:12:33.197 Stocks[905:403] stock Conversion rate = 4.170000

2012-10-26 12:12:33.197 Stocks[905:403] stock NumberOfShare = 7
2012-10-26 12:12:33.198 Stocks[905:403] stock PurchaseSharePrice = 68.489998
2012-10-26 12:12:33.199 Stocks[905:403] stock CurrentSharePrice = 39.049999
2012-10-26 12:12:33.199 Stocks[905:403] stock Conversion rate = 0.590000

2012-10-26 12:12:33.200 Stocks[905:403] stock NumberOfShare = 18
2012-10-26 12:12:33.200 Stocks[905:403] stock PurchaseSharePrice = 27.450001
2012-10-26 12:12:33.201 Stocks[905:403] stock CurrentSharePrice = 91.729996
2012-10-26 12:12:33.201 Stocks[905:403] stock Conversion rate = 4.580000

2012-10-26 12:12:33.201 Stocks[905:403] stock NumberOfShare = 74
2012-10-26 12:12:33.202 Stocks[905:403] stock PurchaseSharePrice = 39.889999
2012-10-26 12:12:33.203 Stocks[905:403] stock CurrentSharePrice = 89.070000
2012-10-26 12:12:33.207 Stocks[905:403] stock Conversion rate = 4.780000

2012-10-26 12:12:33.208 Stocks[905:403] stock NumberOfShare = 58
2012-10-26 12:12:33.208 Stocks[905:403] stock PurchaseSharePrice = 18.709999
2012-10-26 12:12:33.209 Stocks[905:403] stock CurrentSharePrice = 30.000000
2012-10-26 12:12:33.209 Stocks[905:403] stock Conversion rate = 4.590000

2012-10-26 12:12:33.209 Stocks[905:403] stock NumberOfShare = 19
2012-10-26 12:12:33.210 Stocks[905:403] stock PurchaseSharePrice = 38.250000
2012-10-26 12:12:33.210 Stocks[905:403] stock CurrentSharePrice = 88.739998
2012-10-26 12:12:33.211 Stocks[905:403] stock Conversion rate = 2.330000

2012-10-26 12:12:33.211 Stocks[905:403] stock NumberOfShare = 58
2012-10-26 12:12:33.212 Stocks[905:403] stock PurchaseSharePrice = 85.930000
2012-10-26 12:12:33.212 Stocks[905:403] stock CurrentSharePrice = 60.700001
2012-10-26 12:12:33.213 Stocks[905:403] stock Conversion rate = 6.990000

2012-10-26 12:12:33.213 Stocks[905:403] stock NumberOfShare = 18
2012-10-26 12:12:33.214 Stocks[905:403] stock PurchaseSharePrice = 44.689999
2012-10-26 12:12:33.227 Stocks[905:403] stock CurrentSharePrice = 69.220001
2012-10-26 12:12:33.227 Stocks[905:403] stock Conversion rate = 7.940000

2012-10-26 12:12:33.228 Stocks[905:403] stock NumberOfShare = 74
2012-10-26 12:12:33.229 Stocks[905:403] stock PurchaseSharePrice = 51.310001
2012-10-26 12:12:33.229 Stocks[905:403] stock CurrentSharePrice = 68.820000
2012-10-26 12:12:33.230 Stocks[905:403] stock Conversion rate = 3.900000

2012-10-26 12:12:33.230 Stocks[905:403] stock NumberOfShare = 93
2012-10-26 12:12:33.231 Stocks[905:403] stock PurchaseSharePrice = 91.570000
2012-10-26 12:12:33.231 Stocks[905:403] stock CurrentSharePrice = 20.209999
2012-10-26 12:12:33.232 Stocks[905:403] stock Conversion rate = 1.570000

2012-10-26 12:12:33.232 Stocks[905:403] stock NumberOfShare = 75
2012-10-26 12:12:33.233 Stocks[905:403] stock PurchaseSharePrice = 100.470001
2012-10-26 12:12:33.233 Stocks[905:403] stock CurrentSharePrice = 53.310001
2012-10-26 12:12:33.234 Stocks[905:403] stock Conversion rate = 0.210000

2012-10-26 12:12:33.235 Stocks[905:403] stock NumberOfShare = 38
2012-10-26 12:12:33.235 Stocks[905:403] stock PurchaseSharePrice = 40.540001
2012-10-26 12:12:33.236 Stocks[905:403] stock CurrentSharePrice = 30.980000
2012-10-26 12:12:33.236 Stocks[905:403] stock Conversion rate = 3.250000

2012-10-26 12:12:33.237 Stocks[905:403] stock NumberOfShare = 82
2012-10-26 12:12:33.237 Stocks[905:403] stock PurchaseSharePrice = 21.160000
2012-10-26 12:12:33.238 Stocks[905:403] stock CurrentSharePrice = 4.310000
2012-10-26 12:12:33.239 Stocks[905:403] stock Conversion rate = 1.390000

2012-10-26 12:12:33.239 Stocks[905:403] stock NumberOfShare = 97
2012-10-26 12:12:33.240 Stocks[905:403] stock PurchaseSharePrice = 7.380000
2012-10-26 12:12:33.240 Stocks[905:403] stock CurrentSharePrice = 82.180000
2012-10-26 12:12:33.241 Stocks[905:403] stock Conversion rate = 0.210000

2012-10-26 12:12:33.241 Stocks[905:403] stock NumberOfShare = 71
2012-10-26 12:12:33.241 Stocks[905:403] stock PurchaseSharePrice = 70.120003
2012-10-26 12:12:33.242 Stocks[905:403] stock CurrentSharePrice = 88.770004
2012-10-26 12:12:33.242 Stocks[905:403] stock Conversion rate = 6.850000

2012-10-26 12:12:33.243 Stocks[905:403] stock NumberOfShare = 37
2012-10-26 12:12:33.243 Stocks[905:403] stock PurchaseSharePrice = 5.760000
2012-10-26 12:12:33.244 Stocks[905:403] stock CurrentSharePrice = 85.070000
2012-10-26 12:12:33.244 Stocks[905:403] stock Conversion rate = 7.590000

2012-10-26 12:12:33.245 Stocks[905:403] stock NumberOfShare = 58
2012-10-26 12:12:33.255 Stocks[905:403] stock PurchaseSharePrice = 48.989998
2012-10-26 12:12:33.256 Stocks[905:403] stock CurrentSharePrice = 12.270000
2012-10-26 12:12:33.257 Stocks[905:403] stock Conversion rate = 9.500000

2012-10-26 12:12:33.257 Stocks[905:403] stock NumberOfShare = 37
2012-10-26 12:12:33.258 Stocks[905:403] stock PurchaseSharePrice = 68.180000
2012-10-26 12:12:33.258 Stocks[905:403] stock CurrentSharePrice = 10.630000
2012-10-26 12:12:33.259 Stocks[905:403] stock Conversion rate = 0.490000

2012-10-26 12:12:33.259 Stocks[905:403] stock NumberOfShare = 45
2012-10-26 12:12:33.260 Stocks[905:403] stock PurchaseSharePrice = 19.049999
2012-10-26 12:12:33.261 Stocks[905:403] stock CurrentSharePrice = 36.910000
2012-10-26 12:12:33.261 Stocks[905:403] stock Conversion rate = 3.750000

2012-10-26 12:12:33.262 Stocks[905:403] stock NumberOfShare = 56
2012-10-26 12:12:33.262 Stocks[905:403] stock PurchaseSharePrice = 19.889999
2012-10-26 12:12:33.263 Stocks[905:403] stock CurrentSharePrice = 77.930000
2012-10-26 12:12:33.263 Stocks[905:403] stock Conversion rate = 9.180000

2012-10-26 12:12:33.264 Stocks[905:403] stock NumberOfShare = 6
2012-10-26 12:12:33.264 Stocks[905:403] stock PurchaseSharePrice = 90.220001
2012-10-26 12:12:33.265 Stocks[905:403] stock CurrentSharePrice = 89.169998
2012-10-26 12:12:33.265 Stocks[905:403] stock Conversion rate = 0.300000

2012-10-26 12:12:33.266 Stocks[905:403] stock NumberOfShare = 94
2012-10-26 12:12:33.267 Stocks[905:403] stock PurchaseSharePrice = 75.260002
2012-10-26 12:12:33.267 Stocks[905:403] stock CurrentSharePrice = 97.860001
2012-10-26 12:12:33.268 Stocks[905:403] stock Conversion rate = 2.530000

2012-10-26 12:12:33.268 Stocks[905:403] stock NumberOfShare = 44
2012-10-26 12:12:33.269 Stocks[905:403] stock PurchaseSharePrice = 82.139999
2012-10-26 12:12:33.269 Stocks[905:403] stock CurrentSharePrice = 14.790000
2012-10-26 12:12:33.270 Stocks[905:403] stock Conversion rate = 3.770000

2012-10-26 12:12:33.270 Stocks[905:403] stock NumberOfShare = 63
2012-10-26 12:12:33.271 Stocks[905:403] stock PurchaseSharePrice = 75.879997
2012-10-26 12:12:33.272 Stocks[905:403] stock CurrentSharePrice = 26.100000
2012-10-26 12:12:33.272 Stocks[905:403] stock Conversion rate = 7.320000

2012-10-26 12:12:33.273 Stocks[905:403]

the portfolio has a value of \$863458.250000

[/code]

#2

General question, I’m curious why we would need to use the domestic stocks class at all. Since the foreign stock class inherits from the domestic, all that is needed is one array of stocks using the foreign stocks class with the conversionRate set to 1 when domestic.
Is there a compelling reason to present it this way with two classes?

@Roggy67 why did you use a different float for valueInDollars for foreign stocks? You named it valueInDollarsF.

#3

I think the example is trying to demonstrate how one class can extend another class by subclassing it. ForeignStockHolding is StockHolding plus a bit more and thus takes a toll on memory resources since it has to keep track of the conversion rate.

#4

I agree that valueInDollarsF is not needed, and instead all of that can be replaced with valueInDollars, the idea is that the ForeignStockHolding overwrites the previous version. Just as there is not a costInDollarsF there is no need for valueInDollarsF.

I agree with not storing data you don’t need to, so you shouldn’t store conversionRate for non-foreign stocks.

My question with solutions that split foreign + domestic into two arrays is what if you needed them in one array, and if you wanted to output differently based on the type / object?

I figured out how to use respondsToSelector but when the selector but couldn’t use the selector past that!