home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Utilities / ElectronHelper-2.0-MIS / OhmsLawObject.m < prev    next >
Encoding:
Text File  |  1997-02-04  |  4.4 KB  |  201 lines

  1. #import "OhmsLawObject.h"
  2.  
  3. @implementation OhmsLawObject
  4.  
  5. // Global Variables
  6. float VoltsValue;
  7. float AmperesValue;
  8. float OhmsValue;
  9. float WattsValue;
  10.  
  11.  
  12.  
  13. - (void)Calculate:(id)sender
  14. {
  15.  
  16.     // Local Variables
  17.         int WhichOne;
  18.  
  19.     // Assigns the value of the currently selected button
  20.     WhichOne = [FindButton selectedTag]; // Using tag as a reference
  21.  
  22.  
  23.     switch (WhichOne)  { // start switch
  24.  
  25. // Find the Resistance "Ohms"   R=V/I
  26. case 0:
  27.         // Gets the value from the Ampere field
  28.         AmperesValue = [Amperes floatValue];
  29.  
  30.        // Gets the value from the Volts field 
  31.        VoltsValue = [Volts floatValue];
  32.  
  33.        OhmsValue = (VoltsValue/AmperesValue);
  34.  
  35.        [Ohms setFloatValue:OhmsValue];
  36.  
  37.   break;
  38.  
  39. // Find the Current "Ampere"   I= V/R  
  40. case 1:
  41.        // Gets the value from the Ohms field
  42.         OhmsValue = [Ohms floatValue];
  43.  
  44.        // Gets the value from the Volts field
  45.        VoltsValue = [Volts floatValue];
  46.  
  47.        AmperesValue= (VoltsValue/OhmsValue);
  48.  
  49.        [Amperes setFloatValue:AmperesValue];
  50.  
  51.   break;
  52.  
  53. // Find the Voltage "Volt"  V=I*R   
  54. case 2:
  55.       // Gets the value from the Ohms field 
  56.         OhmsValue = [Ohms floatValue];
  57.  
  58.        // Gets the value from the Ampere field 
  59.        AmperesValue = [Amperes floatValue];
  60.  
  61.        VoltsValue= (AmperesValue*OhmsValue);
  62.  
  63.        [Volts setFloatValue:VoltsValue];
  64.  
  65.     break;
  66.  
  67. // Find the Power "Watts" 
  68. case 3:
  69.  
  70.        // Gets the value from the Ohms field
  71.        OhmsValue = [Ohms floatValue];
  72.  
  73.        // Gets the value from the Ampere  field
  74.         AmperesValue = [Amperes floatValue];
  75.  
  76.        // Gets the value from the Volts field
  77.        VoltsValue = [Volts floatValue];
  78.  
  79.  
  80. // Make sure all the values are found then find the Watts
  81.  
  82. //  Find the value for Ohms    
  83. if (OhmsValue == 0)
  84. {
  85.         OhmsValue= (VoltsValue/AmperesValue);
  86.               [Ohms setFloatValue:OhmsValue];
  87. }
  88.  
  89. // Find the value for Amperes    
  90. if (AmperesValue == 0)
  91. {
  92.         AmperesValue= (VoltsValue/OhmsValue);
  93.         [Amperes setFloatValue:AmperesValue];
  94. }
  95.  
  96. //    Find the value for Volts  
  97. if (VoltsValue == 0)
  98. {
  99.         VoltsValue= (AmperesValue*OhmsValue);
  100.         [Volts setFloatValue:VoltsValue];
  101. }
  102.  
  103. // Find the Watts     P=I*V    
  104.  
  105.        WattsValue= (AmperesValue*VoltsValue);
  106.        [Watts setFloatValue:WattsValue];
  107.  
  108.         break;
  109.  
  110.                         } // end switch    
  111.  
  112.     
  113. }
  114.  
  115. - (void)FindAmpere:(id)sender
  116. {
  117.  
  118.     [self SetToZero:sender];
  119.  
  120.     [[CalcTextFields cellAtIndex:0] setTitle:@"Ohms :"];
  121.     [[CalcTextFields cellAtIndex:1] setTitle:@"Amperes :"];
  122.     [[CalcTextFields cellAtIndex:2] setTitle:@"Volts :"];
  123.     [[CalcTextFields cellAtIndex:3] setTitle:@""];
  124.  
  125.     [Ohms setEnabled:YES];
  126.     [Amperes setEnabled:NO];
  127.     [Volts setEnabled:YES];
  128.     [Watts setEnabled:NO];
  129.     
  130. }
  131.  
  132. - (void)FindOhms:(id)sender
  133. {
  134.  
  135.     [self SetToZero:sender]; // Set the form value to ZERO 
  136.  
  137.     [[CalcTextFields cellAtIndex:0] setTitle:@"Ohms :"];
  138.     [[CalcTextFields cellAtIndex:1] setTitle:@"Amperes :"];
  139.     [[CalcTextFields cellAtIndex:2] setTitle:@"Volts :"];
  140.     [[CalcTextFields cellAtIndex:3] setTitle:@""];
  141.  
  142.     [Ohms setEnabled:NO]; // Disable the form (noneditable)
  143.  
  144.     [Amperes setEnabled:YES]; // Enables the form
  145.     [Volts setEnabled:YES]; // Enables the form
  146.  
  147.     [Watts setEnabled:NO]; // Disable the form (noneditable) 
  148.     
  149. }
  150.  
  151. - (void)FindVolts:(id)sender
  152. {
  153.     [self SetToZero:sender];
  154.  
  155.     [[CalcTextFields cellAtIndex:0] setTitle:@"Ohms :"];
  156.     [[CalcTextFields cellAtIndex:1] setTitle:@"Amperes :"];
  157.     [[CalcTextFields cellAtIndex:2] setTitle:@"Volts :"];
  158.     [[CalcTextFields cellAtIndex:3] setTitle:@""];
  159.  
  160.     [Ohms setEnabled:YES];
  161.     [Amperes setEnabled:YES];
  162.     [Volts setEnabled:NO];
  163.     [Watts setEnabled:NO];
  164.     
  165. }
  166.  
  167. - (void)FindWatts:(id)sender
  168. {
  169.  
  170.     [self SetToZero:sender];
  171.  
  172.     [[CalcTextFields cellAtIndex:0] setTitle:@"Ohms :"];
  173.     [[CalcTextFields cellAtIndex:1] setTitle:@"Amperes :"];
  174.     [[CalcTextFields cellAtIndex:2] setTitle:@"Volts :"];
  175.     [[CalcTextFields cellAtIndex:3] setTitle:@"Watts :"];
  176.  
  177.     [Ohms setEnabled:YES];
  178.     [Amperes setEnabled:YES];
  179.     [Volts setEnabled:YES];
  180.     [Watts setEnabled:NO];
  181.     
  182. }
  183.  
  184. - (void)PrintOhmsTable:(id)sender
  185. // This method will print the Ohms Law Table
  186. {
  187.  
  188.          [OhmsTable print:self];
  189. }
  190.  
  191. - (void)SetToZero:(id)sender
  192. // This sets the values of the forms to ZERO
  193. {
  194.             [Ohms setFloatValue:0];
  195.             [Amperes setFloatValue:0];
  196.             [Volts setFloatValue:0];
  197.             [Watts setFloatValue:0];
  198. }
  199.  
  200. @end
  201.