Hi every one, i’d like you to write me a message if the code is very well done or not with the best practices that you recommend. Thanks.
[code]BNRForeignStockHolding.h
#import <Foundation/Foundation.h>
#import “BNRStockHolding.h”
@interface BNRForeignStockHolding : BNRStockHolding
@property (nonatomic) float conversionRate;
- (float)costInDollars; // purchaseSharePrice * numberOfShares
- (float)valueInDollars; // currentSharePrice * numberOFShare
@end[/code]
[code]BNRForeignStockHolding.h
#import “BNRForeignStockHolding.h”
@implementation BNRForeignStockHolding
- (float)costInDollars{
if(self.conversionRate){
return [self purchaseSharePrice] * [self conversionRate];
}else{
return [self purchaseSharePrice] * [self numberOfShares];
}
}
- (float)valueInDollars{
if(self.conversionRate){
return [self currentSharePrice] * [self conversionRate];
}else{
return [self currentSharePrice] * [self numberOfShares];
}
}
@end[/code]
[code]BNRStockHolding.h
#import “BNRStockHolding.h”
@implementation BNRStockHolding
-
(float)costInDollars
{
return [self purchaseSharePrice] * [self numberOfShares];
} -
(float)valueInDollars
{
return [self currentSharePrice] * [self numberOfShares];
}
@end[/code]
[code]BNRStockHolding.m
#import <Foundation/Foundation.h>
@interface BNRStockHolding : NSObject
@property (nonatomic) float purchaseSharePrice;
@property (nonatomic) float currentSharePrice;
@property (nonatomic) int numberOfShares;
- (float)costInDollars; // purchaseSharePrice * numberOfShares
- (float)valueInDollars; // currentSharePrice * numberOFShare
@end[/code]
[code]main.m
#import <Foundation/Foundation.h>
//#import “BNRStockHolding.h”
#import “BNRForeignStockHolding.h”
int main(int argc, const char * argv[])
{
@autoreleasepool {
BNRForeignStockHolding *almacen1 = [[BNRForeignStockHolding alloc] init];
BNRForeignStockHolding *almacen2 = [[BNRForeignStockHolding alloc] init];
BNRForeignStockHolding *almacen4 = [[BNRForeignStockHolding alloc] init];
// Mount of products on almacen1
[almacen1 setPurchaseSharePrice:2.30];
[almacen1 setCurrentSharePrice:4.50];
[almacen1 setNumberOfShares:40];
[almacen1 costInDollars];
[almacen1 numberOfShares];
// Mount of productos on almacen2
[almacen2 setPurchaseSharePrice:2.30];
[almacen2 setCurrentSharePrice:4.50];
[almacen2 setNumberOfShares:40];
[almacen2 costInDollars];
[almacen2 numberOfShares];
[almacen4 setPurchaseSharePrice:2.30];
[almacen4 setCurrentSharePrice:4.50];
[almacen4 setNumberOfShares:40];
[almacen4 setConversionRate:0.94];
[almacen4 costInDollars];
[almacen4 numberOfShares];
NSMutableArray *temp = [NSMutableArray arrayWithObjects:almacen1, almacen2, almacen4, nil];
for(BNRForeignStockHolding *s in temp){
float a = [s purchaseSharePrice];
float b = [s currentSharePrice];
int c = [s numberOfShares];
float d = [s costInDollars];
float e = [s valueInDollars];
float f = [s conversionRate];
if (f){
NSLog(@"\n Purchase Prices: %.2f \n Current Share Price: %.2f \n Number Shares: %d \n Cost in dollars: %.2f \n Values in dollars: %.2f \n conversion %.2f", a, b, c, d, e, f);
}else{
NSLog(@"\n Purchase Prices: %.2f \n Current Share Price: %.2f \n Number Shares: %d \n Cost in dollars: %.2f \n Values in dollars: %.2f", a, b, c, d, e);
}
}
}
return 0;
}[/code]