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

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