Advertisement
BOT_Yokel

ICS3U1 Unit 1 Activity 5: Question 3

Jul 12th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date Completed: July 12, 2017
  2. // Purpose: Calculating the possibility of forming a right angle triangle when given three side lengths
  3.  
  4. // This line makes the button, btnRisk wait for a mouse click
  5. // When the button is clicked, the determineSum function is called
  6. btnDetermine.addEventListener(MouseEvent.CLICK, determineSum);
  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. txtinSideA.addEventListener(MouseEvent.CLICK, clearLabel1);
  11. txtinSideB.addEventListener(MouseEvent.CLICK, clearLabel2);
  12. txtinSideC.addEventListener(MouseEvent.CLICK, clearLabel3);
  13.  
  14. // This is the determineSum function
  15. // e:MouseEvent is the click event experienced by the button
  16. // void indicates that the function does not return a value
  17. function determineSum(e:MouseEvent):void
  18.  
  19. {
  20.     // declare the variables
  21.     var SideA:Number;
  22.     var SideB:Number;
  23.     var SideC:Number;
  24.  
  25.     // get the Side Lengths
  26.     SideA = Number(txtinSideA.text);
  27.     SideB = Number(txtinSideB.text);
  28.     SideC = Number(txtinSideC.text);
  29.  
  30.  
  31.     // determine if the square of a side length is equal to the sum of the remaining two side lengths
  32.     if (SideA * SideA + SideB * SideB == SideC * SideC)
  33.     {  
  34.         lblResult.text = "These sides can make a right-triangle.";
  35.     }
  36.    
  37.     else if (SideB * SideB + SideC * SideC == SideA * SideA)
  38.     {
  39.         lblResult.text = "These sides can make a right-triangle.";
  40.     }
  41.    
  42.     else if (SideC * SideC + SideA * SideA == SideB * SideB)
  43.     {
  44.         lblResult.text = "These sides can make a right-triangle.";
  45.     }
  46.    
  47.     else
  48.     {
  49.         lblResult.text = "These sides cannot make a right-triangle.";
  50.     }
  51. }
  52.  
  53. // This is the clearLabel1 function
  54. // e:MouseEvent is the click event experienced by the textinput
  55. // void indicates that the function does not return a value
  56. function clearLabel1(e:MouseEvent):void
  57.  
  58. {
  59.     lblResult.text = "";
  60.     txtinSideA.text = "";
  61. }
  62.  
  63. // This is the clearLabel2 function
  64. // e:MouseEvent is the click event experienced by the textinput
  65. // void indicates that the function does not return a value
  66. function clearLabel2(e:MouseEvent):void
  67.  
  68. {
  69.     lblResult.text = "";
  70.     txtinSideB.text = "";
  71. }
  72.  
  73. // This is the clearLabel3 function
  74. // e:MouseEvent is the click event experienced by the textinput
  75. // void indicates that the function does not return a value
  76. function clearLabel3(e:MouseEvent):void
  77.  
  78. {
  79.     lblResult.text = "";
  80.     txtinSideC.text = "";
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement