Advertisement
BOT_Yokel

ICS3U1 Unit 1 Activity 5: Question 4

Jul 12th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date Completed: July 12, 2017
  2. // Purpose: Calculating body mass index based on measurements given using the metric or imperial system
  3.  
  4. // This line makes the button, btnRisk wait for a mouse click
  5. // When the button is clicked, the determineBmi function is called
  6. btnDetermine.addEventListener(MouseEvent.CLICK, determineBmi);
  7.  
  8. // This line makes the textinput, txtinLevel wait for a mouse click
  9. // When a textinput is clicked, the clearLabel 1, 2, or 3 functions are called
  10. // When a radio button is clicked, the labels for the measurements are changed
  11. txtinMeasureA.addEventListener(MouseEvent.CLICK, clearLabel1);
  12. txtinMeasureB.addEventListener(MouseEvent.CLICK, clearLabel2);
  13. radMetric.addEventListener(MouseEvent.CLICK, changelabel1);
  14. radImperial.addEventListener(MouseEvent.CLICK, changelabel2);
  15.  
  16. // This is the determineBmi function
  17. // e:MouseEvent is the click event experienced by the button
  18. // void indicates that the function does not return a value
  19. function determineBmi(e:MouseEvent):void
  20.  
  21. {
  22.     // declare the variables
  23.     var MeasureA:Number;
  24.     var MeasureB:Number;
  25.     var System:String;
  26.     var Index:Number;
  27.  
  28.     // get the measurements
  29.     MeasureA = Number(txtinMeasureA.text);
  30.     MeasureB = Number(txtinMeasureB.text);
  31.     // Get the measurement system
  32.     // radMetric.group determines the group that radMetric is in
  33.     // .selectedData gets the value of the RadioButton that is selected from the group
  34.     System = String(radMetric.group.selectedData);
  35.  
  36.     // Calculations
  37.     if (System == "Metric")
  38.     {  
  39.         Index = MeasureA / (MeasureB * MeasureB);
  40.         lblResult.text = Index.toFixed(1)
  41.        
  42.         if (Index > 40)
  43.         {
  44.             lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
  45.         }
  46.        
  47.         else if (Index <= 40 && Index > 30)
  48.         {
  49.             lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
  50.         }
  51.        
  52.         else if (Index <= 30 && Index > 25)
  53.         {
  54.             lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
  55.         }
  56.        
  57.         else if (Index <= 25 && Index >= 18.5)
  58.         {
  59.             lblResultDesc.text = "IDEAL WEIGHT: Make no changes";
  60.         }
  61.        
  62.         else if (Index < 18.5 && Index >= 15)
  63.         {
  64.             lblResultDesc.text = "UNDER WEIGHT: Consider adding calories from your diet";
  65.         }
  66.        
  67.         else if (Index < 15)
  68.         {
  69.             lblResultDesc.text = "UNDER WEIGHT: Consider adding calories from your diet";
  70.         }
  71.     }
  72.    
  73.     // Changing Units
  74.     System = String(radImperial.group.selectedData);
  75.  
  76.     // Calculations
  77.     if (System == "Imperial")
  78.     {  
  79.         Index = (MeasureA *703) / (MeasureB * MeasureB);
  80.         lblResult.text = Index.toFixed(1)
  81.        
  82.         if (Index > 40)
  83.         {
  84.             lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
  85.         }
  86.        
  87.         else if (Index <= 40 && Index > 30)
  88.         {
  89.             lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
  90.         }
  91.        
  92.         else if (Index <= 30 && Index > 25)
  93.         {
  94.             lblResultDesc.text = "OVER WEIGHT: Consider removing calories from your diet";
  95.         }
  96.        
  97.         else if (Index <= 25 && Index >= 18.5)
  98.         {
  99.             lblResultDesc.text = "IDEAL WEIGHT: Make no changes";
  100.         }
  101.        
  102.         else if (Index < 18.5 && Index >= 15)
  103.         {
  104.             lblResultDesc.text = "UNDER WEIGHT: Consider adding calories from your diet";
  105.         }
  106.        
  107.         else if (Index < 15)
  108.         {
  109.             lblResultDesc.text = "UNDER WEIGHT: Consider adding calories from your diet";
  110.         }
  111.     }
  112. }
  113.  
  114. // This is the clearLabel1 function
  115. // e:MouseEvent is the click event experienced by the textinput
  116. // void indicates that the function does not return a value
  117. function clearLabel1(e:MouseEvent):void
  118.  
  119. {
  120.     lblResult.text = "";
  121.     lblResultDesc.text = "";
  122.     txtinMeasureA.text = "";
  123. }
  124.  
  125. // This is the clearLabel2 function
  126. // e:MouseEvent is the click event experienced by the textinput
  127. // void indicates that the function does not return a value
  128. function clearLabel2(e:MouseEvent):void
  129.  
  130. {
  131.     lblResult.text = "";
  132.     lblResultDesc.text = "";
  133.     txtinMeasureB.text = "";
  134. }
  135.  
  136. // This is the changelabel1 function
  137. // e:MouseEvent is the click event experienced by the textinput
  138. // void indicates that the function does not return a value
  139. function changelabel1(e:MouseEvent):void
  140.  
  141. {
  142.     lblPrompt1.text = "Enter your weight in kilograms:";
  143.     lblPrompt2.text = "Enter your height in metres:";
  144.     lblResult.text = "";
  145.     lblResultDesc.text = "";
  146.     txtinMeasureA.text = "";
  147.     txtinMeasureB.text = "";
  148.    
  149. }
  150.  
  151. // This is the changelabel2 function
  152. // e:MouseEvent is the click event experienced by the textinput
  153. // void indicates that the function does not return a value
  154. function changelabel2(e:MouseEvent):void
  155.  
  156. {
  157.     lblPrompt1.text = "Enter your weight in pounds:";
  158.     lblPrompt2.text = "Enter your height in inches:";
  159.     lblResult.text = "";
  160.     lblResultDesc.text = "";
  161.     txtinMeasureA.text = "";
  162.     txtinMeasureB.text = "";
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement