Challenge

Create a new Foundation Command Line Tool called Stocks. Then create a class called BNRStockHolding to represent a stock that you have purchased. It will be a subclass of NSObject. For instance variables, it will have two floats named _purchaseSharePrice and _currentSharePrice and one int named _numberOfShares. Use properties to create accessor methods and instance variables. Create two other instance methods:

-​ ​(​f​l​o​a​t​)​c​o​s​t​I​n​D​o​l​l​a​r​s​;​ ​ ​/​/​ ​p​u​r​c​h​a​s​e​S​h​a​r​e​P​r​i​c​e​ ​*​ ​n​u​m​b​e​r​O​f​S​h​a​r​e​s​
-​ ​(​f​l​o​a​t​)​v​a​l​u​e​I​n​D​o​l​l​a​r​s​;​ ​/​/​ ​c​u​r​r​e​n​t​S​h​a​r​e​P​r​i​c​e​ ​*​ ​n​u​m​b​e​r​O​f​S​h​a​r​e​s​

In main(), fill an array with three instances of BNRStockHolding. Then iterate through the array printing out the value of each.

Figure 18.4  An array of BNRStockHolding objects

An array of BNRStockHolding objects
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset