home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Financial / Emerald1.0 / Source / USObject.m < prev   
Encoding:
Text File  |  1996-03-02  |  5.6 KB  |  163 lines

  1.  
  2. #import "USObject.h"
  3.  
  4. @implementation USObject
  5.  
  6. // AWAKEFROMNIB
  7. // This is one of the last methods executed after the nib file is loaded.
  8. // This is the BEST way I know how to initialize an object and jump into
  9. // a method after the nib file was loaded, because you are all the methods
  10. // and variables needed can be used. (Unlike init which is not compeletly
  11. // ready when that message is sent
  12. - awakeFromNib
  13. {
  14.  
  15.     [CalcWindow makeKeyAndOrderFront:NULL];
  16.     [StockPrice selectText:self];
  17.  
  18.         return self;
  19. }
  20.  
  21.  
  22.  
  23. - Calc:sender
  24. {
  25.  
  26.     //Assign Misc Variables
  27.         char dummyString[20];
  28.         int WhichOne;
  29.  
  30.         
  31.     //Assign CalcWindow Variables
  32.     float stockprice;
  33.         float numberofshares;
  34.         float totalstockprice;
  35.         float totalcommission;
  36.         float total;
  37.     float netamountpershare;
  38.  
  39.     stockprice = [StockPrice floatValue];
  40.     numberofshares = [NumberOfShares floatValue];
  41.  
  42.  
  43. // Take the value in Stock Price * Number of Shares and display
  44. // the result in the Total Stock Price textfield
  45. totalstockprice = [StockPrice floatValue] * [NumberOfShares floatValue];
  46.     sprintf(dummyString, "%.2f", totalstockprice); 
  47.     [TotalStockPrice setStringValue:dummyString];// Display result
  48.  
  49. // Figure out the commission rate and then do the calculations
  50.  
  51. // Checks if the stock price is below Stock1 if yes then
  52. // calculates the commission using Comm1
  53. if ([StockPrice floatValue] <= [Stock2 floatValue]) totalcommission = (([StockPrice floatValue] * [NumberOfShares floatValue]) * ([Comm1 floatValue] / 100));
  54.  
  55. // Checks if the stock price is >=Stock3 and <= Stock4 if yes then
  56. // calculates the commission by adding Comm2 and multiplying
  57. // Comm3 by the number of shares
  58. if ([StockPrice floatValue] >= [Stock3 floatValue] && [StockPrice floatValue] <= [Stock4 floatValue]) totalcommission = ([Comm2 floatValue] + ([NumberOfShares floatValue] * [Comm3 floatValue]));
  59.  
  60. // Checks if the stock price is >=Stock5 and <= Stock6 if yes then
  61. // calculates the commission by adding Comm4 and multiplying
  62. // Comm5 by the number of shares
  63. if ([StockPrice floatValue] >= [Stock5 floatValue] && [StockPrice floatValue] <= [Stock6 floatValue]) totalcommission = ([Comm4 floatValue] + ([NumberOfShares floatValue] * [Comm5 floatValue]));
  64.  
  65. // Checks if the stock price is >=Stock7 and <= Stock8 if yes then
  66. // calculates the commission by adding Comm6 and multiplying
  67. // Comm7 by the number of shares
  68. if ([StockPrice floatValue] >= [Stock7 floatValue] && [StockPrice floatValue] <= [Stock8 floatValue]) totalcommission = ([Comm6 floatValue] + ([NumberOfShares floatValue] * [Comm7 floatValue]));
  69.  
  70. // Checks if the stock price is >=Stock9 and <= Stock10 if yes then
  71. // calculates the commission by adding Comm8 and multiplying
  72. // Comm9 by the number of shares
  73. if ([StockPrice floatValue] >= [Stock9 floatValue] && [StockPrice floatValue] <= [Stock10 floatValue]) totalcommission = ([Comm8 floatValue] + ([NumberOfShares floatValue] * [Comm9 floatValue]));
  74.  
  75. // Checks if the stock price is >=Stock11 and <= Stock12 if yes then
  76. // calculates the commission by adding Comm10 and multiplying
  77. // Comm11 by the number of shares
  78. if ([StockPrice floatValue] >= [Stock11 floatValue] && [StockPrice floatValue] <= [Stock12 floatValue]) totalcommission = ([Comm10 floatValue] + ([NumberOfShares floatValue] * [Comm11 floatValue]));
  79.  
  80. // Checks if the stock price is >=Stock13 and <= Stock14 if yes then
  81. // calculates the commission by adding Comm12 and multiplying
  82. // Comm13 by the number of shares
  83. if ([StockPrice floatValue] >= [Stock13 floatValue] && [StockPrice floatValue] <= [Stock14 floatValue]) totalcommission = ([Comm12 floatValue] + ([NumberOfShares floatValue] * [Comm13 floatValue]));
  84.  
  85. // Checks if the stock price is >=Stock15 if yes then
  86. // calculates the commission by adding Comm14 and multiplying
  87. // Comm15 by the number of shares
  88. if ([StockPrice floatValue] >= [Stock15 floatValue]) totalcommission = ([Comm14 floatValue] + ([NumberOfShares floatValue] * [Comm15 floatValue]));
  89.  
  90.  
  91.     // Assign variables
  92.     totalstockprice = [TotalStockPrice floatValue];
  93.  
  94.     // Transactions with principal values less than Principl Value 
  95.         //will be charged a flat fee of FlatFee
  96.         if ([TotalStockPrice floatValue] <= [PrincipalValue floatValue]) totalcommission = [FlatFee floatValue];
  97.  
  98.  
  99.     // Assigns the value of the currently selected radio button
  100.      // using tag as a reference
  101.        WhichOne = [RadioButton selectedTag]; 
  102.     if (WhichOne == 2)  totalcommission = totalcommission -(totalcommission * ([TeleMaxInput floatValue] / 100));
  103.  
  104.     // Assigns the value of the currently selected radio button
  105.      // using tag as a reference
  106.        WhichOne = [BuySellRadio selectedTag]; 
  107.     if (WhichOne == 1)  total = totalstockprice + totalcommission;
  108.     if (WhichOne == 2)  total = totalstockprice - totalcommission;
  109.     
  110.     // Display Total Commission 
  111.     // Convert float to a string
  112.     sprintf(dummyString, "%.2f", totalcommission); 
  113.     [TotalCommission setStringValue:dummyString];// Display result
  114.  
  115.     // Display Net Amount
  116.     sprintf(dummyString, "%.2f", total); // Convert float to a string
  117.     [Total setStringValue:dummyString];// Display result
  118.  
  119.     // Calculate Net Amount Per Share
  120.     // Number of Shares / Net Amount = Net Amount per Share
  121.     netamountpershare =  [Total floatValue] / [NumberOfShares floatValue];
  122.     // Display Net Amount per Share
  123.     sprintf(dummyString, "%.2f", netamountpershare);
  124.     [NetAmountPerShare setStringValue:dummyString];// Display result
  125.     [NetAmountPerShare display];
  126.  
  127.     [StockPrice selectText:self];
  128.  
  129.  
  130.     return self;
  131. }
  132.  
  133.  
  134. - PrintCalc:sender
  135. {
  136.  
  137.     [CalcWindow printPSCode:self];
  138.  
  139.     return self;
  140. }
  141.  
  142. - PrintCommSchedule:sender
  143. {
  144.  
  145.     [CommissionWindow printPSCode:self];
  146.  
  147.     return self;
  148. }
  149.  
  150. - TeleMax:sender
  151. {
  152.     return self;
  153. }
  154.  
  155. - DirectTrading:sender
  156. {
  157.     return self;
  158. }
  159.  
  160.  
  161.  
  162. @end
  163.