貸款計算機C#實現 課程作業一

來源:互聯網
上載者:User

標籤:nbsp   convert   nta   pos   lin   str   send   event   false   

花了兩個小時理解公式,我數學是不是太弱了..

 

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 貸款電腦{    public partial class Form1 : Form    {        int pos = 0;        double year, cost, temp;//分別表示 年限 金額 利率        public Form1()        {            InitializeComponent();        }        //pos == 1 表示等額本息        private void checkBox1_CheckedChanged(object sender, EventArgs e)        {            if(checkBox1.Checked )            {                checkBox2.Checked = false;                pos = 1;            }            else                pos = 0;        }        //pos == 2 表示等額本金        private void checkBox2_CheckedChanged(object sender, EventArgs e)        {            if (checkBox2.Checked)            {                checkBox1.Checked = false;                pos = 1;            }            else                pos = 0;        }        //計算按鈕        private void button1_Click(object sender, EventArgs e)        {                        try //選擇還款方式            {                if ( pos == 0)                    throw new Exception ();            }            catch (Exception)            {                MessageBox.Show("先選擇還款方式才能進行此運算!", "錯誤", MessageBoxButtons.OK);            }            try //輸入貸款年限            {                year = Convert.ToDouble(textBox1.Text);                year = year * 12;//轉換成貸款月份            }            catch (Exception)            {                MessageBox.Show("先輸入貸款年限才能進行此運算!", "錯誤", MessageBoxButtons.OK);            }            try  //輸入貸款金額            {                cost = Convert.ToDouble(textBox2.Text);                cost = cost * 10000;// 貸款金額,單位元            }            catch (Exception)            {                MessageBox.Show("先輸入貸款金額才能進行此運算!", "錯誤", MessageBoxButtons.OK);            }            try  //輸入貸款利率            {                temp = Convert.ToDouble(textBox3.Text);                temp = temp / 1200;//貸款月利率            }            catch (Exception)            {                MessageBox.Show("先輸入貸款利率才能進行此運算!", "錯誤", MessageBoxButtons.OK);            }            textBox4.Text = "";            textBox5.Text = "";            textBox6.Text = "";            if (checkBox1.Checked)            {                double temp1 = cost * temp*Math.Pow(1 + temp, year+1) / (Math.Pow(1+temp,year) -1);//*temp * cost                double temp2 = temp1 * year -cost;                double temp3 = temp1 * year;                textBox4.Text = temp1.ToString();                textBox5.Text = temp2.ToString();                textBox6.Text = temp3.ToString();            }            else if(checkBox2.Checked)            {                double temp1 = ((cost / year + cost * temp) + cost / year * (1 + temp)) / 2 ; //總利息                double temp2 = temp1 * year - cost ;                double temp3 = temp1 * year;                textBox4.Text = temp1.ToString();                textBox5.Text = temp2.ToString();                textBox6.Text = temp3.ToString();            }        }        private void button2_Click(object sender, EventArgs e)        {            try //選擇還款方式            {                if (pos == 0)                    throw new Exception();            }            catch (Exception)            {                MessageBox.Show("先選擇還款方式才能進行此運算!", "錯誤", MessageBoxButtons.OK);            }            try //輸入貸款年限            {                year = Convert.ToDouble(textBox1.Text);                year = year * 12;//轉換成貸款月份            }            catch (Exception)            {                MessageBox.Show("先輸入貸款年限才能進行此運算!", "錯誤", MessageBoxButtons.OK);            }            try  //輸入貸款金額            {                cost = Convert.ToDouble(textBox2.Text);                cost = cost * 10000;// 貸款金額,單位元            }            catch (Exception)            {                MessageBox.Show("先輸入貸款金額才能進行此運算!", "錯誤", MessageBoxButtons.OK);            }            try  //輸入貸款利率            {                temp = Convert.ToDouble(textBox3.Text);                temp = temp / 1200;//貸款月利率            }            catch (Exception)            {                MessageBox.Show("先輸入貸款利率才能進行此運算!", "錯誤", MessageBoxButtons.OK);            }            textBox4.Text = "";            textBox5.Text = "";            textBox6.Text = "";            if (checkBox1.Checked)            {                double temp1 = cost * temp * Math.Pow(1 + temp, year + 1) / (Math.Pow(1 + temp, year) - 1);//*temp * cost                double temp2 = temp1 * year - cost;                double temp3 = temp1 * year;                textBox4.Text = temp1.ToString();                textBox5.Text = temp2.ToString();                textBox6.Text = temp3.ToString();            }            else if (checkBox2.Checked)            {                double temp1 = ((cost / year + cost * temp) + cost / year * (1 + temp)) / 2; //總利息                double temp2 = temp1 * year - cost ;                double temp3 = temp1 * year;                textBox4.Text = temp1.ToString();                textBox5.Text = temp2.ToString();                textBox6.Text = temp3.ToString();            }        }    }}

 

貸款計算機C#實現 課程作業一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.