Interest Caculator

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            decimal benjin, toal;
            double rate, time;
            try
            {
                benjin = Convert.ToDecimal(capitalBox.Text);
                rate = Convert.ToDouble(rateBox.Text);
                time = Convert.ToDouble(timeBox.Text);
            }

           catch (Exception )
            {
                MessageBox .Show ("输入数据不正确,请检查!");
                capitalBox.Clear();
                rateBox .Clear ();
                timeBox .Clear ();
                return;
            }
            if (benjin < 0 || rate < 0 || time < 0)
            {
                MessageBox.Show("输入数据应该为正数,请检查!");
                capitalBox.Clear();
                rateBox .Clear ();
                timeBox .Clear ();
                return;
            }

            if (simple.Checked)
            {
                toal = benjin + benjin * (decimal)((rate / 100) * time);
                showBox.Text = Convert.ToString(toal);
            }
            else 
            {
                toal = benjin * (decimal)Math.Pow(1 + rate / 100, time);
                showBox.Text = Convert.ToString(toal);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            capitalBox.Clear();
            rateBox .Clear ();
            timeBox .Clear ();
            showBox.Clear();
           
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

   //在Form里先选中KeyPreview设置为true
      private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.C)
                count.PerformClick();  //如果按下ctrl+C键,则点击计算按钮
               
            if (e.KeyCode == Keys.R)
                reset.PerformClick();

            if (e.KeyCode == Keys.E)                 exist.PerformClick();

                  }               }     }

 

Assignment 1

Deadline: 10 Oct., 2012

Objective

1. To be familiar with the Visual C# / Visual Studio environment

2. To design a simple graphical user interface

3. To perform some simple calculations using Visual C#

Task

In this assignment, your task is to use Visual C# to develop a GUI-based interest calculator.  You have to design the user interface.  Your program has to:

· Ask the user to select either simple interest or compound interest

· Ask the user to enter the principal

You can assume that the user’s input has already been rounded to the nearest dollar. Example: 1340

· Ask the user to enter the interest rate per year

For example, if the user enters 3.5, the user means 3.5% p.a.

· Ask the user to enter the loan period in years

You can assume that the loan period is a whole number

Example: 15

· Include three buttons:

The “Calculate” button (Hotkey: C)

§ When the user clicks this button or presses the corresponding hotkey, the program will output the total amount (principal + total interest) in an appropriate location. You can assume that all the required fields have been filled before the user presses this button.

The “Reset” button (Hotkey: R)

§ When the user clicks this button or presses the corresponding hotkey, all the user inputs will be cleared (or set to the default value).

The “Exit” button (Hotkey: E)

§ When the user clicks this button or presses the corresponding hotkey, the program terminates.

Note: One can press Alt+Hotkey to click a button.

In addition, you can assume that the user inputs are always valid.

Let APr, and t be the total amount, the principal, the interest rate (p.a.), and the number of years respectively.  The formula for calculating the simple interest is shown as follows:

A=P+P*r*t

The formula for calculating the compound interest is shown as follows:

A=p*(1+r)^t

Assessment Scheme

· Correctness 80%

· User interface design 10%

E.g. clarity, convenience

· Program readability 10%

E.g. comments, indentation, meaningful variable names

Interest Caculator

 

Testing Platform

We will test your program in the following platform:

· Windows XP

· Visual C# 2008/2010 Express

If you develop your project in other platforms, please DO test it in the platform mentioned above in the lab before submitting it.

你可能感兴趣的:(C#,interest,Caculator)