简介:

为银行存款客户提供一个超级计算器,简单直观操作界面,提供一个银行本意到期金额结算查询程序,方便用户选择存款方式。

功能截图:

实验步骤:利用工具栏建造窗体设计如图;

1.建立2个GroupBox控件,左侧GroupBox放入四个label标签,分别表明“存款金额(元),年利率(%),存期(年),利息计算方式,”

2 放入3个TextBox分别对应“存款金额(元),年利率(%),存期(年)”,将其属性 Name 改为“textBoxstartAmount,textBoxYearRate,textBoxYears”

3.放入 ComboBox下拉框对应利息计算方式,属性“Name”改为“comboBoxCalculateType”

4.放入button控件,属性 text改为“计算”,Name改为“buttonOK”

5.右侧放入2个label,属性Name 改为“labelParameter,labelResult”

6.进行代码编写“:

 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 Superalculator2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
string[] caclType = { "按月计算","按季度计算","按年计算"};
comboBoxCalculateType.Items.AddRange(caclType);
comboBoxCalculateType.SelectedIndex = ;
labelResult.Text = string.Empty;//保证修改任意输入值时,不显示计算结果
} private void Form1_Shown(object sender,EventArgs e)
{
textBoxStarAmount.Focus();
} private void buttonOK_Click(object sender, EventArgs e)
{
//存款金额
int startAmount; //年利率 float yearRate; //存期
int years;
if(!ConvertStringToNumber(textBoxStarAmount .Text,true ,out startAmount ) )
{
MessageBox.Show("存款金额输入有错", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
} if(startAmount <)
{
MessageBox.Show("存款金额不得少于100元","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
if(ConvertStringToNumber(textBoxYearRate.Text ,true ,out yearRate )== false ) {
MessageBox.Show("年利率输入有错","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning );
return; }
yearRate /= 100.0f;
if(ConvertStringToNumber (textBoxYears .Text ,true ,out years)== false )
{
MessageBox.Show("存期(年)输入有误","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
} if (comboBoxCalculateType.SelectedIndex == -) {
MessageBox.Show("请选择提供的利息计算方式","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
labelParameter.Text =
string.Format("存款金额:{0}元{3}{3}年利率:{1}%{3}{3}存期:{2}年",
startAmount ,yearRate *,years,Environment .NewLine ); //labelResult.Text = string.Format("到期结算结果:{0:F2}元", Caculate(startAmount, yearRate / 12, years * 12));
switch (comboBoxCalculateType.SelectedItem.ToString())
{
case "按月计算":
labelResult.Text = string.Format("到期结算金额;{0:F2}元",
Caculate(startAmount, yearRate / , years * ) );
break ;
case "按季度计算":
labelResult.Text = string.Format("到期结算金额{0:F2}元",
Caculate(startAmount, yearRate / , years * ));
break;
case "按年计算":
labelResult.Text = string.Format("到期结算金额{0:F2}元",
Caculate(startAmount, yearRate, years));
break;
}
}
private void groupBox1_Enter(Object sender ,EventArgs e)
{
labelParameter.Text = string.Empty;
labelResult.Text = string.Empty;
} private float Caculate(int startAmount, float rate,int count)
{
//throw new NotImplementedException();
float total = startAmount;
for (int i = ; i <= count; i++)
{
total += total * rate;
}
return total;
} /// <summary>
/// 将字符串转化为32位整数
/// </summary>
/// <param name="s">被被转化的字符</param>
/// <param name="mustGreatThanZero">是否必须大于0的要求</param>
/// <param name="result">转化后的结果</param>
/// <returns></returns> private bool ConvertStringToNumber(string s, bool mustGreatThanZero, out int result)
{
// throw new NotImplementedException();
if (int.TryParse(s, out result) == false)
{
return false;
}
else if (mustGreatThanZero && result <= )
{
return false;
}
return true;
}
/// <summary>
/// 将字符串转化为32位整数
/// </summary>
/// <param name="s">被被转化的字符</param>
/// <param name="mustGreatThanZero">是否必须大于0的要求</param>
/// <param name="result">转化后的结果</param>
/// <returns></returns> private bool ConvertStringToNumber(string s,bool mustGreatThanZero,out float result)
{
if (float.TryParse(s, out result) == false)
{
return false;
}
if (mustGreatThanZero && result <= )
{
return false;
}
return true;
}

实验总结:实验参考书籍《C#程序设计上机指导与实例解析》 。

知识点:switch语句应用,字符串转化为整数。swlectedItem 调用下拉框内容,Message。Show("",""MessageBoxButtons.OK,MessageBoxIcon.Warning)警告提示语句;labelResult.Text = string.Empty;//保证修改任意输入值时,不显示计算结果;

c#0银行存款计算器的更多相关文章

  1. iOS UI基础-1.0加法计算器

    1.打开Xcode,新建一个项目 2.Single View Application是最适合初学者的模板 3.填写该应用相关信息 4.搭建UI界面 项目创建完毕后,自动帮我们做了很多配置,也自动生成了 ...

  2. Pyqt QTabWidget 简单的计算器集合

    今天我们简单介绍下QTabWidget,然后在加入Demo计算器 首先我先讲下文件的结构: 文件分四部分, 一部分是Ui设计文件, 一部分是由Ui生成的py文件, 一部分是 计算器的逻辑文件,  最后 ...

  3. 计算器显示e-005什么意思

    计算器显示e-005什么意思 1e-005是科学表达式,即 =1e-5 =0.00001e+005就是乘以10的5次方 就是-1.4989*10^5 这是科学计数法(也叫指数计数法)   这是科学计数 ...

  4. SWT/RAP计算器

    /** *2.测试 */ public class NofTest extends AbstractEntryPoint {        Text text,text2;    RemoteObje ...

  5. JS 实现计算器功能

    括号功能未实现,后续更 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  6. 【转】qtp-learn

    1.计算器的例子(手动添加,将结果写到日志文件中) SystemUtil.Run "C:\WINDOWS\system32\calc.exe",""," ...

  7. spell checking

    Spell checker Description You, as a member of a development team for a new spell checking program, a ...

  8. python[练习题]:实现Base64编码

    要求自己实现算法,不用库. Base64简介: Base64是一种用64个字符来表示任意二进制数据的方法. 用记事本打开exe.jpg.pdf这些文件时,我们都会看到一大堆乱码,因为二进制文件包含很多 ...

  9. 20165312 2017-2018-2 《JAVA程序设计》第3周学习总结

    20165312 2017-2018-2 <JAVA程序设计>第3周学习总结 一.第四章知识点总结 1.类 类的实现包括两个部分:类声明和类体. class是关键字,用来定义类. clas ...

随机推荐

  1. IOS--UIAlertView的使用方法详细

    IOS--UIAlertView的使用方法详细   // UIAlertView的常用方法 // 标准样式 UIAlertView *oneAlertView = [[UIAlertView allo ...

  2. How to use PhotoshopApplication in maxscript

    未完待续 ps_app= createOLEObject "Photoshop.Application" ps_app.Load "d:\\test\\aaa.tga&q ...

  3. 转:尝试用Gearman实现分布式处理(PHP)

    原文来自于http://blog.csdn.net/fdipzone/article/details/7166520 本文需要你已对Gearman有个大致了解. 顺便再推荐两篇参考文章http://h ...

  4. Stockbroker Grapevine

    http://poj.org/problem?id=1125 #include<cstdio> #include<cstring> #include<cmath> ...

  5. [Android] 输入系统(三):加载按键映射

    映射表基本概念 由于Android调用getEvents得到的key是linux发送过来的scan code,而Android处理的是类似于KEY_UP这种统一类型的key code,因此需要有映射表 ...

  6. 【转】HashMap和HashSet的区别

    原文网址:http://www.importnew.com/6931.html HashMap和HashSet的区别是Java面试中最常被问到的问题.如果没有涉及到Collection框架以及多线程的 ...

  7. MYSQL转MSSQL

    SSMA 2008 for MySQL 1.0.exe SSMA 2008 for MySQL 1.0 Extension Pack.exe mysql-connector-odbc-5.1.11-w ...

  8. Promise in AngularJS

    What's promise Angular’s event system provides a lot of power to our Angular apps. One of the most p ...

  9. qt之treeview例子

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.Qt import * from PyQt4. ...

  10. struts2校验器规范错误解决

    今天struts2的校验器的配置文件文件头出现了错误,配置如下: <!DOCTYPE validators PUBLIC        "-//OpenSymphony Group// ...