Interest Rate Calculator Using Web Application In TypeScript

Introduction

 
The following article calculates interest rates. In this program, we have two text boxes, one textbox for the amount and another textbox for the interest rate which is applied to the original amount. Let's use the following procedure.
 
Step 1
Open Visual Studio 2012 and click "File" -> "New" -> "Project...". A window is opened. In this window, click "HTML Application for TypeScript" under Visual C#.
 
Give your application the name "Interest_Rate_Calculator" and then click "Ok".
 
Step 2
After Step 1, right-click on "Interest_Rate_Calculator". A pop-up window is opened. Click on  "Add" -> "New Item" -> "Web From". Give your WebForm the name "Interest_Rate_Calculator_Demo.aspx" and then click "Ok".
 
Step 3
The project will have been created; a new window is opened on the right side. This window is called the Solution Explorer. The Solution Explorer contains the ts file, js file, CSS file, and aspx files.
 

Coding

 
ShowImage.ts
  1. class Rate_Calculator {  
  2.  RateCalculate(amount: number, rate: number) {  
  3.   var interest, total;  
  4.   interest = amount * (rate / 100);  
  5.   total = amount + interest;  
  6.   var div = document.getElementById("Display1");  
  7.   div.innerText = "Amount ->" + amount + "\n" + "Interest -> " + rate + "%" + "\n" + "Interest paid -> " + interest + "\n" + "Total(A+IP) -> " + total;  
  8.  }  
  9. }  
  10. window.onload = () => {  
  11.  var obj = new Rate_Calculator();  
  12.  var bttn = document.getElementById("Calculate");  
  13.  bttn.onclick = function() {  
  14.   var amount = ( < HTMLInputElement > document.getElementById("Amount")).value;  
  15.   var rate = ( < HTMLTextAreaElement > document.getElementById("Rate")).value;  
  16.   if (amount.length == 0 || rate.length == 0) {  
  17.    var div = document.getElementById("Display");  
  18.    div.innerText = "All Fields are required";  
  19.   } else {  
  20.    var amount1 = parseInt(amount);  
  21.    var rate1 = parseInt(rate);  
  22.    obj.RateCalculate(amount1, rate1);  
  23.   }  
  24.  }  
  25. };  
ShowImage.aspx
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Interest_Calculator_Demo.aspx.cs" Inherits="Interest_Rate_Calculater.Interest_Calculator_Demo" %>  
  2.  <  
  3.  !DOCTYPE html >  
  4.  <  
  5.  html xmlns = "http://www.w3.org/1999/xhtml" >  
  6.  <  
  7.  head runat = "server" >  
  8.  <  
  9.  title > < /title>  
  10.  <  
  11.  script src = "app.js" > < /script>  
  12.  <  
  13.  /head>  
  14.  <  
  15.  body >  
  16.  <  
  17.  form id = "form1"  
  18. style = "color:#0094ff"  
  19. runat = "server" >  
  20.  <  
  21.  div >  
  22.  <  
  23.  asp: Label ID = "Label1"  
  24. runat = "server"  
  25. Text = "Interest Rate Calculator In TypeScript "  
  26. Font - Bold = "True"  
  27. Font - Italic = "True"  
  28. Font - Size = "Large"  
  29. ForeColor = "Blue" > < /asp:Label>  
  30.  <  
  31.  /div> 
  32.  <  
  33.  /form>  
  34.  <  
  35.  p style = "font-weight: bold" >  
  36.  Enter Amount & nbsp;  
  37. <  
  38. input id = "Amount"  
  39. type = "text" / > < /p>  
  40.  <  
  41.  p style = "font-weight: bold" >  
  42.  Interest Rate & nbsp; & nbsp; & nbsp;  
  43. <  
  44. input id = "Rate"  
  45. type = "text" / > < /p>  
  46.  <  
  47.  p >  
  48.  <  
  49.  input id = "Calculate"  
  50. style = "font-weight: bold; color: #800000;"  
  51. type = "button"  
  52. value = "Calculate" / > < /p>  
  53.  <  
  54.  div id = "Display"  
  55. style = "font-weight: bold; font-size: large; color: #FF0000" > < /div>  
  56.  <  
  57.  div id = "Display1"  
  58. style = "font-size: large; font-weight: bold; color:#3d6f12" > < /div>  
  59.  <  
  60.  /body>  
  61.  <  
  62.  /html>  
app.js
  1. var Rate_Calculator = (function() {  
  2.  function Rate_Calculator() {}  
  3.  Rate_Calculator.prototype.RateCalculate = function(amount, rate) {  
  4.   var interest, total;  
  5.   interest = amount * (rate / 100);  
  6.   total = amount + interest;  
  7.   var div = document.getElementById("Display1");  
  8.   div.innerText = "Amount ->" + amount + "\n" + "Interest -> " + rate + "%" + "\n" + "Interest paid -> " + interest + "\n" + "Total(A+IP) -> " + total;  
  9.  };  
  10.  return Rate_Calculator;  
  11. })();  
  12. window.onload = function() {  
  13.  var obj = new Rate_Calculator();  
  14.  var bttn = document.getElementById("Calculate");  
  15.  bttn.onclick = function() {  
  16.   var amount = (document.getElementById("Amount")).value;  
  17.   var rate = (document.getElementById("Rate")).value;  
  18.   if (amount.length == 0 || rate.length == 0) {  
  19.    var div = document.getElementById("Display");  
  20.    div.innerText = "All Fields are required";  
  21.   } else {  
  22.    var amount1 = parseInt(amount);  
  23.    var rate1 = parseInt(rate);  
  24.    obj.RateCalculate(amount1, rate1);  
  25.   }  
  26.  };  
  27. };  
Output 1
 
Then run the page which will look as:
 
First-Image.gif
 
Output 2
 
Now enter the values and click on the Calculate button, which shows the following output after calculation:
 
final-output.gif
 
Output 3
 
Now run the application and click on the Calculate button without entering the values which shows the following error:
 
Required-Field-Image.gif
 
Referenced By
 
http://www.c-sharpcorner.com/UploadFile/0c1bb2/interest-rate-calculator-using-Asp-Net-C-Sharp/


Similar Articles