简介:

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

功能截图:

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

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. 简单又强大的联发科手机PhilZ Touch Recovery安装器,详细教程 - 本文出自高州吧

    原文地址:http://bbs.gaozhouba.com/thread-19355-1-1.html * * * * * * * * * * * * * * * * * * * * * * * * ...

  2. 用UltraEdit折叠宏定义

    在UltraEdit中通过“高级->配置->导航->编辑器显示->语法高亮->文档的完整目录名称”取得“c_cplusplus.uew”文件存放的目录. 在“c_cplu ...

  3. flex中validateall()方法, 多Item验证 ,结果统一提示

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  4. 创建组合索引SQL从1个多小时到1S的案例

    select aa.acct_org, aa.loan_acct_no, aa.FUNCTIONARY, aa.cust_no, sum(dwm.pkg_tools.currcdtran(bb.INT ...

  5. POJPower Network (最大流)

    题目链接. 分析: 这题描述的可不是一般的复杂. 其时就是很多源点.很多汇点,使尽量多流量的到达汇点. 因为有很多源点,就再设一个源点(0号),使得0号到其它源点的容量为其它源点的初始量,同样设一汇点 ...

  6. HTML5 Web socket和socket.io

    what is websockets Two-way communication over ont TCP socket, a type of PUSH technology HTML5的新特性,用于 ...

  7. HDFS基础和java api操作

    1. 概括 适合一次写入多次查询情况,不支持并发写情况 通过hadoop shell 上传的文件存放在DataNode的block中,通过linux shell只能看见block,看不见文件(HDFS ...

  8. NET设计模式(2):单件模式(Singleton Pattern)[转载]

    单件模式(Singleton Pattern) ——.NET设计模式系列之二 Terrylee,2005年12月07日 概述 Singleton模式要求一个类有且仅有一个实例,并且提供了一个全局的访问 ...

  9. HBase技术介绍

    HBase简介 HBase - Hadoop Database,是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBase技术可在廉价PC Server上搭建起大规模结构化存储集群. HB ...

  10. python学习笔记(集合的使用)

    集合 集合(set):把不同的元素组成一起形成集合,是python基本的数据类型. 集合元素(set elements):组成集合的成员 为什么需要集合? 集合的作用 1 .列表去重复数据 按照现有知 ...