Challenge

Create new Foundation Command Line Tool called Stocks. Then create a class called StockHolding 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. Create accessor methods for the 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 StockHolding. Then iterate through the array printing out the value of each.

Figure 17.2  An array of StockHolding objects

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

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