Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date Completed: July 13, 2017
- // Purpose: Calculating total amount invested at a fixed interest rate over a maximum of 15 years
- // This line makes the button, btnCalculate wait for a mouse click
- // When the button is clicked, the determineTotal function is called
- btnCalculate.addEventListener(MouseEvent.CLICK, determineTotal);
- // This line makes the textinputs: txtinInvestment, txtinDuration, and txtinRate, wait for a mouse click
- // When a textinput is clicked, the clearLabel 1, 2, or 3 functions are called
- txtinInvestment.addEventListener(MouseEvent.CLICK, clearLabel1);
- txtinRate.addEventListener(MouseEvent.CLICK, clearLabel2);
- txtinDuration.addEventListener(MouseEvent.CLICK, clearLabel3);
- // This is the determineTotal function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function determineTotal(e:MouseEvent):void
- {
- //Clear the output labels so that it won't stack the output when the button is pressed again
- lblYears.text = "";
- lblAmount.text = "";
- lblInterest.text = "";
- lblTotal.text = "";
- //Declare the variables for the while statements, preset a counter for 1, preset Total to be 0
- var Investment:Number;
- var Rate:Number;
- var Duration:Number;
- var Total:Number = 0;
- var Counter:Number = 1;
- var Interest:Number;
- var Amount:Number;
- //Set the variables to equal the values from the text input boxes
- Investment = Number(txtinInvestment.text)
- Rate = Number(txtinRate.text)
- Duration = Number(txtinDuration.text)
- //Introduce the while statement for calculating total amount invested at a fixed interest rate
- while (Counter <= Duration && Counter <= 15)
- {
- //Output the Year, and the corresponding account value, interest from account value, and total
- lblYears.text += String(Counter) + "\r";
- //Total initially set to 0 so that the amount could be calculated without a pre-existing total
- Amount = Total + Investment
- lblAmount.text += Amount.toFixed(2) + "\r";
- Interest = (Rate / 100) * Amount
- lblInterest.text += Interest.toFixed(2) + "\r";
- Total = Interest + Amount
- lblTotal.text += Total.toFixed(2) + "\r";
- Counter += 1
- }
- }
- // This is the clearLabel1 function
- // e:MouseEvent is the click event experienced by the textinput
- // void indicates that the function does not return a value
- function clearLabel1(e:MouseEvent):void
- {
- lblYears.text = "";
- lblAmount.text = "";
- lblInterest.text = "";
- lblTotal.text = "";
- txtinInvestment.text = "";
- }
- // This is the clearLabel2 function
- // e:MouseEvent is the click event experienced by the textinput
- // void indicates that the function does not return a value
- function clearLabel2(e:MouseEvent):void
- {
- lblYears.text = "";
- lblAmount.text = "";
- lblInterest.text = "";
- lblTotal.text = "";
- txtinRate.text = "";
- }
- // This is the clearLabel3 function
- // e:MouseEvent is the click event experienced by the textinput
- // void indicates that the function does not return a value
- function clearLabel3(e:MouseEvent):void
- {
- lblYears.text = "";
- lblAmount.text = "";
- lblInterest.text = "";
- lblTotal.text = "";
- txtinDuration.text = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement