Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date: July 20, 2017
- // Purpose: To calculate the gross wages of an employee
- // This line makes the button, btnCalculate wait for a mouse click
- // When the button is clicked, the calculateWages function is called
- btnCalculate.addEventListener(MouseEvent.CLICK, calculateWages);
- // These lines make the textinputs wait for a mouse click
- // When any of these components are clicked, the clearLabels function is called
- txtinHourlyRate.addEventListener(MouseEvent.CLICK, clearLabels);
- txtinNumberHours.addEventListener(MouseEvent.CLICK, clearLabels);
- // Declare Global Variables
- var hourlyRate:Number; // the hourly rate of pay
- var numberHours:Number; // number of hours worked in a week
- var grossWages:Number; // the gross wages
- // This is the calculateWages function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function calculateWages(e:MouseEvent):void
- {
- getData();
- calculateGrossWages(hourlyRate,numberHours);
- lblOutput.text = "Gross Wages $" + grossWages.toFixed(2);
- }
- // This is function calculateGrossWages
- // r - hourly rate
- // h – number of hours
- // It calculates the gross wages
- function calculateGrossWages(r:Number, h:Number)
- {
- // Enter the code here
- if (h <= 40)
- {
- grossWages = (r * h)
- }
- if (h > 40)
- {
- grossWages = (h - 40) * (1.5 * r) + (r * 40)
- }
- }
- // This is the getData function
- // It gets the hourly rate and number of hours from the user
- function getData()
- {
- hourlyRate = Number(txtinHourlyRate.text);
- numberHours = Number(txtinNumberHours.text);
- }
- // This is the clearLabels function
- // e:MouseEvent is the click event experienced by the textInput
- // void indicates that the function does not return a value
- function clearLabels(e:MouseEvent):void
- {
- lblOutput.text = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement