home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / YellowBox / Utilities / BMI-5.0-w / ImperialObject.m < prev    next >
Encoding:
Text File  |  1998-03-15  |  7.0 KB  |  225 lines

  1. #import "ImperialObject.h"
  2.  
  3. @implementation ImperialObject
  4.  
  5. - (void)awakeFromNib
  6. // This is one of the last methods executed after the nib file is loaded.
  7. // This is the Best way to initialize an object and jump into
  8. // a method after the nib file was loaded.
  9. {
  10.         [BMIPanel center];
  11.         [BMIPanel makeKeyAndOrderFront:NULL];
  12.         [WeightTextField selectText:self];
  13. }
  14.  
  15.  
  16. - (void)Calc:(id)sender
  17. {
  18.  
  19.     // Decalare Variables
  20.  
  21.         float weight;
  22.         float height;
  23.         float heightInt;
  24.         float index;
  25.         float gender;
  26.         float agegroup;
  27.         float dummyValue;
  28.  
  29.     // Assign variables
  30.  
  31.          heightInt = [HeightTextField intValue];
  32.             weight = [WeightTextField intValue];
  33.  
  34.     // Calculatate BMI and display BMI
  35.  
  36.             // Convert Inches into feet
  37.             height = heightInt / 12;
  38.  
  39.             // From Pound to Kilogram
  40.             dummyValue = (weight*0.453);
  41.             weight = dummyValue;
  42.  
  43.             // From Feet to Meter
  44.             dummyValue = (0.3048*height);
  45.             height = dummyValue;
  46.  
  47.             index = (weight/(height*height));
  48.  
  49.             // Display BMI index number
  50.             
  51.                 // Sets TextField as a NSFloatType
  52.                 [[IndexTextField cell] setEntryType:NSFloatType];
  53.                 
  54.                 // Format the TextField with two number at the left of the floating point
  55.                 // and two numbers at the right of the floating point.
  56.                 [[IndexTextField cell] setFloatingPointFormat:NO left:2 right:2];
  57.                 
  58.                 [IndexTextField setDoubleValue:index];// Display result
  59.                 [IndexTextField display];
  60.             
  61.                 // Used for MiscKit Gauge  [IndexGauge setDoubleValue:index];// Display result
  62.                 // Used for MiscKit Gauge  [IndexGauge display];
  63.  
  64.  
  65.             // Gender Male = 1, female = 2
  66.             gender = [GenderButton selectedTag];
  67.  
  68.             // Age Group < 18 = 1, 20-29 = 2, >29 = 3
  69.             agegroup = [AgeGroupButton selectedTag];
  70.  
  71.             // Figure out in what category the person is in
  72.             // and display the status for that person.
  73.  
  74.             // Below 18, male, normal
  75.             if ((agegroup == 1) && (gender == 1) && (index < 22))    
  76.             {
  77.                 [StatusTextField setStringValue:@"Normal"];
  78.                 [StatusTextField setTextColor:[NSColor greenColor]];
  79.             };
  80.  
  81.             // Below 18, male, overweight
  82.             if ((agegroup == 1) && (gender == 1) && (index > 22))    
  83.             {
  84.                 [StatusTextField setStringValue:@"Over weight"];
  85.                 [StatusTextField setTextColor:[NSColor redColor]];
  86.             };
  87.  
  88.             // Below 18, female, normal
  89.             if ((agegroup == 1) && (gender == 2) && (index < 20))    
  90.             {
  91.                 [StatusTextField setStringValue:@"Normal"];
  92.                 [StatusTextField setTextColor:[NSColor greenColor]];
  93.             };
  94.  
  95.             // Below 18, female, overweight
  96.             if ((agegroup == 1) && (gender == 2) && (index > 20))    
  97.             {
  98.                 [StatusTextField setStringValue:@"Over weight"];
  99.                 [StatusTextField setTextColor:[NSColor redColor]];
  100.             };
  101.  
  102.  
  103.  
  104.             // 20-29, Male, under weight
  105.             if ((agegroup == 2) && (gender == 1) && (index < 20))    
  106.             {
  107.                 [StatusTextField setStringValue:@"Under weight"];
  108.                 [StatusTextField setTextColor:[NSColor yellowColor]];
  109.             };
  110.  
  111.             // 20-29, male, normal
  112.             if ((agegroup == 2) && (gender == 1) && (index < 27.8) && (index > 20))
  113.             {
  114.                 [StatusTextField setStringValue:@"Normal"];
  115.                 [StatusTextField setTextColor:[NSColor greenColor]];
  116.             };
  117.  
  118.             // 20-29, male, over weight
  119.             if ((agegroup == 2) && (gender == 1) && (index > 27.8))
  120.             {
  121.                 [StatusTextField setStringValue:@"Over weight"];
  122.                 [StatusTextField setTextColor:[NSColor redColor]];
  123.             };
  124.  
  125.             // 20-29, female, under weight
  126.             if ((agegroup == 2) && (gender == 2) && (index < 20))    
  127.             {
  128.                 [StatusTextField setStringValue:@"Under weight"];
  129.                 [StatusTextField setTextColor:[NSColor yellowColor]];
  130.             };
  131.  
  132.  
  133.             // 20-29, female, normal
  134.             if ((agegroup == 2) && (gender == 2) && (index < 27.3) && (index > 20))
  135.             {
  136.                 [StatusTextField setStringValue:@"Normal"];
  137.                 [StatusTextField setTextColor:[NSColor greenColor]];
  138.             };
  139.  
  140.             // 20-29, female, over weight
  141.             if ((agegroup == 2) && (gender == 2) && (index > 27.3))
  142.             {
  143.                 [StatusTextField setStringValue:@"Over weight"];
  144.                 [StatusTextField setTextColor:[NSColor redColor]];
  145.             };
  146.  
  147.  
  148.  
  149.             // Over 29, Male, under weight
  150.             if ((agegroup == 3) && (gender == 1) && (index < 20))    
  151.             {
  152.                 [StatusTextField setStringValue:@"Under weight"];
  153.                 [StatusTextField setTextColor:[NSColor yellowColor]];
  154.             };
  155.  
  156.  
  157.             // Over 29, male, normal
  158.             if ((agegroup == 3) && (gender == 1) && (index < 25) && (index > 20))
  159.             {
  160.                 [StatusTextField setStringValue:@"Normal"];
  161.                 [StatusTextField setTextColor:[NSColor greenColor]];
  162.             };
  163.  
  164.             // Over 29, male, over weight
  165.             if ((agegroup == 3) && (gender == 1) && (index > 25))
  166.             {
  167.                 [StatusTextField setStringValue:@"Over weight"];
  168.                 [StatusTextField setTextColor:[NSColor redColor]];
  169.             };
  170.  
  171.             // Over 29, female, under weight
  172.             if ((agegroup == 3) && (gender == 2) && (index < 20))    
  173.             {
  174.                 [StatusTextField setStringValue:@"Under weight"];
  175.                 [StatusTextField setTextColor:[NSColor yellowColor]];
  176.             };
  177.  
  178.  
  179.             // Over 29, female, normal
  180.             if ((agegroup == 3) && (gender == 2) && (index < 24) && (index > 20))
  181.             {
  182.                 [StatusTextField setStringValue:@"Normal"];
  183.                 [StatusTextField setTextColor:[NSColor greenColor]];
  184.             };
  185.  
  186.             // Over 29, female, over weight
  187.             if ((agegroup == 3) && (gender == 2) && (index > 24))
  188.             {
  189.                 [StatusTextField setStringValue:@"Over weight"];
  190.                 [StatusTextField setTextColor:[NSColor redColor]];
  191.             };
  192.  
  193.     
  194.     
  195. }
  196.  
  197. - (void)HeightRadioInput:(id)sender
  198. {
  199.  
  200.     // Assign variables
  201.     int feetinput;
  202.     int inchesinput;
  203.     float convertedinches;
  204.     float height;
  205.  
  206.     // Assigns the value of the currently selected button
  207.     feetinput = [FeetButton selectedTag];
  208.  
  209.     // Assigns the value of the currently selected button
  210.     inchesinput = [InchesButton selectedTag];
  211.  
  212.     // Convert inches fraction (5/10) to floating point (0.50)
  213.  
  214.     convertedinches = feetinput * 12;
  215.     height = inchesinput + convertedinches;
  216.  
  217.     // Display Height in the Height textfield
  218.     [HeightTextField setIntValue:height];// Display result
  219.     [HeightTextField display];
  220.  
  221.     
  222. }
  223.  
  224. @end
  225.