diff options
Diffstat (limited to 'future_value1/FutureValue/frmFutureValue.cs')
-rw-r--r-- | future_value1/FutureValue/frmFutureValue.cs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/future_value1/FutureValue/frmFutureValue.cs b/future_value1/FutureValue/frmFutureValue.cs new file mode 100644 index 0000000..2853365 --- /dev/null +++ b/future_value1/FutureValue/frmFutureValue.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FutureValue +{ + public partial class frmFutureValue : Form + { + public frmFutureValue() + { + InitializeComponent(); + } + + private void btnCalculate_Click(object sender, EventArgs e) + { + decimal monthlyInvestment = Convert.ToDecimal(txtMonthlyInvestment.Text); + decimal yearlyInterestRate = Convert.ToDecimal(txtInterestRate.Text); + int years = Convert.ToInt32(txtYears.Text); + + int months = years * 12; + decimal monthlyInterestRate = yearlyInterestRate / 12 / 100; + + decimal futureValue = this.CalculateFutureValue( + monthlyInvestment, monthlyInterestRate, months); + txtFutureValue.Text = futureValue.ToString("c"); + txtMonthlyInvestment.Focus(); + } + + private decimal CalculateFutureValue(decimal monthlyInvestment, + decimal monthlyInterestRate, int months) + { + decimal futureValue = 0m; + for (int i = 0; i < months; i++) + futureValue = (futureValue + monthlyInvestment) + * (1 + monthlyInterestRate); + return futureValue; + } + + private void ClearFutureValue(object sender, EventArgs e) + { + txtFutureValue.Text = ""; + } + + private void frmFutureValue_DoubleClick(object sender, EventArgs e) + { + txtMonthlyInvestment.Text = ""; + txtInterestRate.Text = ""; + txtYears.Text = ""; + txtFutureValue.Text = ""; + txtMonthlyInvestment.Focus(); + } + + private void txtInterestRate_DoubleClick(object sender, EventArgs e) + { + txtInterestRate.Text = "12"; + } + private void txtYears_DoubleClick(object sender, EventArgs e) + { + if (txtYears.Text == "") + txtYears.Text = "1"; + else + txtYears.Text = (int.Parse(txtYears.Text) + + 1).ToString(); + } + + private void btnExit_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} |