form1.cs

来自「C#的程序,一个初学者可以看的程序,对高级程序编写者是没有必要的,是关于银行问题」· CS 代码 · 共 62 行

CS
62
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LoanCalculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //一年有12个月
            const int MONTHS_IN_YEAR=12;
            //存储年得率
            float annualInterestRate;
            //贷款周期,一年有多少个数的总数
            int loanPeriod,numberOfPayments;
            //贷款总数,月该付款,总付款
            decimal loanAmount,monthlyPayment,totalPayment;
            //贷款的月利息
            double monthlyInterestRate;
            string output="";
            //输入贷款数目
            loanAmount=decimal.Parse(textBox1.Text);
            //输入年利息
            annualInterestRate=Single.Parse(textBox3.Text);
            //输入贷款周期
            loanPeriod=Int32.Parse(textBox2.Text);


           //求月利息
            monthlyInterestRate = annualInterestRate / 100.0 / MONTHS_IN_YEAR;
            //月付款
            numberOfPayments = loanPeriod * MONTHS_IN_YEAR;
            //月付款
            monthlyPayment=(loanAmount*(decimal)monthlyInterestRate)/(1-(decimal)(Math.Pow((1+monthlyInterestRate),-numberOfPayments)));
            //总付款
            totalPayment=monthlyPayment*numberOfPayments;
            output+=string.Format("{0,-10}{1,-1}{2,9}{3,16:c}{4,16:c}",
                loanAmount,loanPeriod,annualInterestRate,monthlyPayment,totalPayment);
            textBox4.Text+="\n"+output;



        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?