Advertisement
BOT_Yokel

ICS3U1 Unit 1 Activity 6: Question 2

Jul 13th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date Completed: July 13, 2017
  2. // Purpose: Calculating total amount invested at a fixed interest rate over a maximum of 15 years
  3.  
  4. // This line makes the button, btnCalculate wait for a mouse click
  5. // When the button is clicked, the determineTotal function is called
  6. btnCalculate.addEventListener(MouseEvent.CLICK, determineTotal);
  7.  
  8. // This line makes the textinputs: txtinInvestment, txtinDuration, and txtinRate, wait for a mouse click
  9. // When a textinput is clicked, the clearLabel 1, 2, or 3 functions are called
  10. txtinInvestment.addEventListener(MouseEvent.CLICK, clearLabel1);
  11. txtinRate.addEventListener(MouseEvent.CLICK, clearLabel2);
  12. txtinDuration.addEventListener(MouseEvent.CLICK, clearLabel3);
  13.  
  14. // This is the determineTotal 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 determineTotal(e:MouseEvent):void
  18.  
  19. {
  20.     //Clear the output labels so that it won't stack the output when the button is pressed again
  21.     lblYears.text = "";
  22.     lblAmount.text = "";
  23.     lblInterest.text = "";
  24.     lblTotal.text = "";
  25.  
  26.     //Declare the variables for the while statements, preset a counter for 1, preset Total to be 0
  27.     var Investment:Number;
  28.     var Rate:Number;
  29.     var Duration:Number;
  30.     var Total:Number = 0;
  31.     var Counter:Number = 1;
  32.     var Interest:Number;
  33.     var Amount:Number;
  34.    
  35.     //Set the variables to equal the values from the text input boxes
  36.     Investment = Number(txtinInvestment.text)
  37.     Rate = Number(txtinRate.text)
  38.     Duration = Number(txtinDuration.text)
  39.    
  40.     //Introduce the while statement for calculating total amount invested at a fixed interest rate
  41.     while (Counter <= Duration && Counter <= 15)
  42.     {
  43.         //Output the Year, and the corresponding account value, interest from account value, and total
  44.         lblYears.text += String(Counter) + "\r";
  45.         //Total initially set to 0 so that the amount could be calculated without a pre-existing total
  46.         Amount = Total + Investment
  47.         lblAmount.text += Amount.toFixed(2) + "\r";
  48.         Interest = (Rate / 100) * Amount
  49.         lblInterest.text += Interest.toFixed(2) + "\r";
  50.         Total = Interest + Amount
  51.         lblTotal.text += Total.toFixed(2) + "\r";
  52.         Counter += 1
  53.     }
  54. }
  55.  
  56. // This is the clearLabel1 function
  57. // e:MouseEvent is the click event experienced by the textinput
  58. // void indicates that the function does not return a value
  59. function clearLabel1(e:MouseEvent):void
  60.  
  61. {
  62.     lblYears.text = "";
  63.     lblAmount.text = "";
  64.     lblInterest.text = "";
  65.     lblTotal.text = "";
  66.     txtinInvestment.text = "";
  67. }
  68.  
  69. // This is the clearLabel2 function
  70. // e:MouseEvent is the click event experienced by the textinput
  71. // void indicates that the function does not return a value
  72. function clearLabel2(e:MouseEvent):void
  73.  
  74. {
  75.     lblYears.text = "";
  76.     lblAmount.text = "";
  77.     lblInterest.text = "";
  78.     lblTotal.text = "";
  79.     txtinRate.text = "";
  80. }
  81.  
  82. // This is the clearLabel3 function
  83. // e:MouseEvent is the click event experienced by the textinput
  84. // void indicates that the function does not return a value
  85. function clearLabel3(e:MouseEvent):void
  86.  
  87. {
  88.     lblYears.text = "";
  89.     lblAmount.text = "";
  90.     lblInterest.text = "";
  91.     lblTotal.text = "";
  92.     txtinDuration.text = "";
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement