Advertisement
BOT_Yokel

ICS3U1 Unit 2 Activity 3: Question 2

Jul 20th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date: July 20, 2017
  2. // Purpose: To calculate the gross wages of an employee
  3.  
  4. // This line makes the button, btnCalculate wait for a mouse click
  5. // When the button is clicked, the calculateWages function is called
  6. btnCalculate.addEventListener(MouseEvent.CLICK, calculateWages);
  7.  
  8. // These lines make the textinputs wait for a mouse click
  9. // When any of these components are clicked, the clearLabels function is called
  10. txtinHourlyRate.addEventListener(MouseEvent.CLICK, clearLabels);
  11. txtinNumberHours.addEventListener(MouseEvent.CLICK, clearLabels);
  12.  
  13. // Declare Global Variables
  14. var hourlyRate:Number;     // the hourly rate of pay
  15. var numberHours:Number;    // number of hours worked in a week
  16. var grossWages:Number;     // the gross wages
  17.    
  18. // This is the calculateWages function
  19. // e:MouseEvent is the click event experienced by the button
  20. // void indicates that the function does not return a value
  21. function calculateWages(e:MouseEvent):void
  22. {  
  23.     getData();
  24.     calculateGrossWages(hourlyRate,numberHours);
  25.     lblOutput.text = "Gross Wages $" + grossWages.toFixed(2);
  26. }
  27.  
  28. // This is function calculateGrossWages
  29. // r - hourly rate
  30. // h – number of hours
  31. // It calculates the gross wages
  32. function calculateGrossWages(r:Number, h:Number)
  33. {
  34.     // Enter the code here
  35.     if (h <= 40)
  36.     {  
  37.         grossWages = (r * h)
  38.     }
  39.    
  40.     if (h > 40)
  41.     {
  42.         grossWages = (h - 40) * (1.5 * r) + (r * 40)
  43.     }
  44.  
  45. }
  46.  
  47. // This is the getData function
  48. // It gets the hourly rate and number of hours from the user
  49. function getData()
  50. {
  51.     hourlyRate = Number(txtinHourlyRate.text);
  52.     numberHours = Number(txtinNumberHours.text);
  53. }
  54.  
  55. // This is the clearLabels function
  56. // e:MouseEvent is the click event experienced by the textInput
  57. // void indicates that the function does not return a value
  58. function clearLabels(e:MouseEvent):void
  59. {
  60.      lblOutput.text = "";
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement