Help me with this challenge


#1

Im close to solving this challenge but i need help on the last part.

I just need to add the value of my Usd Port and my Php Portfolio to the All Stocks Portfolio here are my code

Portfolio.m

[code]//
// Porfolio.m
// Stocks
//
// Created by malcantara on 12/11/13.
// Copyright © 2013 malcantara. All rights reserved.
//

#import “Porfolio.h”
#import “StockHolding.h”
#import “ForeignStockHolding.h”
@implementation Porfolio
@synthesize stockPortfolio, totalValue;

-(void)addStocktoArray:(StockHolding *)p{
if(!stockPortfolio){
stockPortfolio = [[NSMutableArray alloc]init];
}
[stockPortfolio addObject:p];
}
-(void)addStocktoPhpArray:(StockHolding *)f{
if (!stockPhpPortfolio){
stockPhpPortfolio = [[NSMutableArray alloc]init];
}
[stockPhpPortfolio addObject:f];
}
-(float)valueOfPortfolio{
float sum = 0.0;

for (ForeignStockHolding *a in stockPortfolio){
    sum+= [a valueInDollars];
}
return sum;

}
-(float)valueOfPhpPortfolio{
float sum = 0.0;

for(ForeignStockHolding *p in stockPortfolio){
    sum+= [p valueInPhp];
}
return (sum);

}

@end
[/code]

Portfolio.h

[code]//
// Portfolio.h
// Stocks
//
// Created by malcantara on 12/11/13.
// Copyright © 2013 malcantara. All rights reserved.
//

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

@interface Porfolio : NSObject{
NSMutableArray *stockPortfolio;
NSMutableArray *stockPhpPortfolio;
float totalValue;
}
@property (strong) NSMutableArray *stockPortfolio;
@property (strong) NSMutableArray *stockPhpPortfolio;
@property float totalValue;

-(void)addStocktoArray:(StockHolding *)p;
-(void)addStocktoPhpArray:(StockHolding *)f;
-(float)valueOfPortfolio;
-(float)valueOfPhpPortfolio;

@end
[/code]

ForeignStockholding.h

[code]//
// ForeignStockHolding.h
// Stocks
//
// Created by malcantara on 12/3/13.
// Copyright © 2013 malcantara. All rights reserved.
//

#import <Foundation/Foundation.h>
#import “StockHolding.h”
@interface ForeignStockHolding : StockHolding
{
float Php;
float UsDollar;
float conversionRate;
float sharePriceinPhp;
float currentPriceinPhp;
}

@property float conversionRate;

-(float)costInPhp;
-(float)valueInPhp;

@end
[/code]

ForeignStockholding.m

[code]//
// StockHolding.m
// Stocks
//
// Created by malcantara on 11/19/13.
// Copyright © 2013 malcantara. All rights reserved.
//

#import “StockHolding.h”

@implementation StockHolding

-(float)sharePrice
{
return sharePrice;
}
-(void)setpurchaseSharePrice:(float)p
{
sharePrice = p;
}
-(float)currentPrice
{
return currentPrice;
}
-(void)setcurrentSharePrice:(float)c
{
currentPrice = c;
}
-(int) shareNumber
{
return shareNumber;
}
-(void)setnumberOfShares:(int)n
{
shareNumber = n;
}
-(float)costInDollars
{
return (sharePrice * shareNumber);
}
-(float)valueInDollars
{
return (currentPrice * shareNumber);
}

@end
[/code]

Stockholding.h

[code]//
// StockHolding.h
// Stocks
//
// Created by malcantara on 11/19/13.
// Copyright © 2013 malcantara. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface StockHolding : NSObject
{
float sharePrice;
float currentPrice;
int shareNumber;
}
-(float) sharePrice;
-(void)setpurchaseSharePrice:(float)p;
-(float) currentPrice;
-(void)setcurrentSharePrice:(float)c;
-(int) shareNumber;
-(void)setnumberOfShares:(int)n;

-(float)costInDollars;
-(float)valueInDollars;

@end
[/code]

Stockholding.m

[code]//
// StockHolding.m
// Stocks
//
// Created by malcantara on 11/19/13.
// Copyright © 2013 malcantara. All rights reserved.
//

#import “StockHolding.h”

@implementation StockHolding

-(float)sharePrice
{
return sharePrice;
}
-(void)setpurchaseSharePrice:(float)p
{
sharePrice = p;
}
-(float)currentPrice
{
return currentPrice;
}
-(void)setcurrentSharePrice:(float)c
{
currentPrice = c;
}
-(int) shareNumber
{
return shareNumber;
}
-(void)setnumberOfShares:(int)n
{
shareNumber = n;
}
-(float)costInDollars
{
return (sharePrice * shareNumber);
}
-(float)valueInDollars
{
return (currentPrice * shareNumber);
}

@end
[/code]

main.m

[code]//
// main.m
// Stocks
//
// Created by malcantara on 11/19/13.
// Copyright © 2013 malcantara. All rights reserved.
//

#import <Foundation/Foundation.h>
#import “ForeignStockHolding.h”
#import “StockHolding.h”
#import "Porfolio.h"
int main(int argc, const char * argv[])
{

@autoreleasepool {
    
    Porfolio *AllPortfolio = [[Porfolio alloc]init];
    Porfolio *UsdPortfolio = [[Porfolio alloc]init];
    Porfolio *PhpPortfolio = [[Porfolio alloc]init];
    
    //USD Stocks
    
    ForeignStockHolding *stockNumber1 = [[ForeignStockHolding alloc] init];
    
    [stockNumber1 setpurchaseSharePrice:2.30];
    [stockNumber1 setcurrentSharePrice:4.50];
    [stockNumber1 setnumberOfShares:40];
    [stockNumber1 setConversionRate:43.78];
    
    [AllPortfolio addStocktoArray:stockNumber1];
    [UsdPortfolio addStocktoArray:stockNumber1];
    [PhpPortfolio addStocktoArray:stockNumber1];
    
    
    ForeignStockHolding *stockNumber2 = [[ForeignStockHolding alloc] init];
    
    [stockNumber2 setpurchaseSharePrice:12.19];
    [stockNumber2 setcurrentSharePrice:10.56];
    [stockNumber2 setnumberOfShares:90];
    [stockNumber2 setConversionRate:43.78];
    
    [AllPortfolio addStocktoArray:stockNumber2];
    [UsdPortfolio addStocktoArray:stockNumber2];
    [PhpPortfolio addStocktoArray:stockNumber2];
    
    
    ForeignStockHolding *stockNumber3 = [[ForeignStockHolding alloc] init];
    
    [stockNumber3 setpurchaseSharePrice:45.10];
    [stockNumber3 setcurrentSharePrice:49.51];
    [stockNumber3 setnumberOfShares:210];
    [stockNumber3 setConversionRate:43.78];
    
    [AllPortfolio addStocktoArray:stockNumber3];
    [UsdPortfolio addStocktoArray:stockNumber3];
    [PhpPortfolio addStocktoArray:stockNumber3];

    //Php Stocks
    
    ForeignStockHolding *stockPhpNumber1 = [[ForeignStockHolding alloc] init];
    
    [stockNumber1 setpurchaseSharePrice:2.30];
    [stockNumber1 setcurrentSharePrice:4.50];
    [stockNumber1 setnumberOfShares:40];
    [stockNumber1 setConversionRate:43.78];
    
    [AllPortfolio addStocktoArray:stockPhpNumber1];
    [UsdPortfolio addStocktoArray:stockPhpNumber1];
    [PhpPortfolio addStocktoArray:stockPhpNumber1];
    
    ForeignStockHolding *stockPhpNumber2 = [[ForeignStockHolding alloc] init];
    
    [stockNumber2 setpurchaseSharePrice:12.19];
    [stockNumber2 setcurrentSharePrice:10.56];
    [stockNumber2 setnumberOfShares:90];
    [stockNumber2 setConversionRate:43.78];
    
    [AllPortfolio addStocktoArray:stockPhpNumber2];
    [UsdPortfolio addStocktoArray:stockPhpNumber2];
    [PhpPortfolio addStocktoArray:stockPhpNumber2];
    
    ForeignStockHolding *stockPhpNumber3 = [[ForeignStockHolding alloc] init];
    
    [stockNumber3 setpurchaseSharePrice:45.10];
    [stockNumber3 setcurrentSharePrice:49.51];
    [stockNumber3 setnumberOfShares:210];
    [stockNumber3 setConversionRate:43.78];
    
    [AllPortfolio addStocktoArray:stockPhpNumber3];
    [UsdPortfolio addStocktoArray:stockPhpNumber3];
    [PhpPortfolio addStocktoArray:stockPhpNumber3];

    
    NSArray *stocksList = [NSArray arrayWithObjects:stockNumber1, stockNumber2, stockNumber3, nil];
    
    for(ForeignStockHolding *p in stocksList) {
   
    NSLog(@"Michael bought %i Shares for a total of $%.2f and it will be sold for a total value of $%.2f",[p shareNumber] , [p costInDollars], [p valueInDollars]);
    
        NSLog(@"%i shares will be bought for a total of %.2fPhp and sold for %.2fPhp", [p shareNumber], [p costInPhp], [p valueInPhp]);
        }
    
    NSLog(@"Value of All Portfolios: $%.2f", [AllPortfolio valueOfPortfolio]);
    NSLog(@"Value of USD Portfolio: $%.2f", [UsdPortfolio valueOfPortfolio]);
    NSLog(@"Value of Php Portfolio: $%.2f", [PhpPortfolio valueOfPhpPortfolio]);
}

return 0;

}[/code]

I really need the help :slight_smile: