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

实验步骤:利用工具栏建造窗体设计如图;
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银行存款计算器的更多相关文章
- iOS UI基础-1.0加法计算器
		
1.打开Xcode,新建一个项目 2.Single View Application是最适合初学者的模板 3.填写该应用相关信息 4.搭建UI界面 项目创建完毕后,自动帮我们做了很多配置,也自动生成了 ...
 - Pyqt   QTabWidget 简单的计算器集合
		
今天我们简单介绍下QTabWidget,然后在加入Demo计算器 首先我先讲下文件的结构: 文件分四部分, 一部分是Ui设计文件, 一部分是由Ui生成的py文件, 一部分是 计算器的逻辑文件, 最后 ...
 - 计算器显示e-005什么意思
		
计算器显示e-005什么意思 1e-005是科学表达式,即 =1e-5 =0.00001e+005就是乘以10的5次方 就是-1.4989*10^5 这是科学计数法(也叫指数计数法) 这是科学计数 ...
 - SWT/RAP计算器
		
/** *2.测试 */ public class NofTest extends AbstractEntryPoint { Text text,text2; RemoteObje ...
 - JS 实现计算器功能
		
括号功能未实现,后续更 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
 - 【转】qtp-learn
		
1.计算器的例子(手动添加,将结果写到日志文件中) SystemUtil.Run "C:\WINDOWS\system32\calc.exe",""," ...
 - spell checking
		
Spell checker Description You, as a member of a development team for a new spell checking program, a ...
 - python[练习题]:实现Base64编码
		
要求自己实现算法,不用库. Base64简介: Base64是一种用64个字符来表示任意二进制数据的方法. 用记事本打开exe.jpg.pdf这些文件时,我们都会看到一大堆乱码,因为二进制文件包含很多 ...
 - 20165312 2017-2018-2 《JAVA程序设计》第3周学习总结
		
20165312 2017-2018-2 <JAVA程序设计>第3周学习总结 一.第四章知识点总结 1.类 类的实现包括两个部分:类声明和类体. class是关键字,用来定义类. clas ...
 
随机推荐
- 【HDOJ】2772 Matchsticks
			
纯粹的找规律题.1: 22: 53: 54: 45: 56: 67: 38: 79: 60: 6 2 1 13 7 74 4 115 2 ...
 - 【HDOJ】4983 Goffi and GCD
			
题意说的非常清楚,即求满足gcd(n-a, n)*gcd(n-b, n) = n^k的(a, b)的不同对数.显然gcd(n-a, n)<=n, gcd(n-b, n)<=n.因此当n不为 ...
 - COJN 0583 800602分苹果
			
800602分苹果 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放, ...
 - 强联通  HDU 1269
			
第一道强联通的题目纪念一下! 主要是模版 tarjan算法 #include <iostream> #include <cstdlib> #include <cstdio ...
 - C# .NET开发Oracle数据库应用程序
			
.NET Framework访问Oracle数据库至少有两种方式,一种是利用微软提供的ADO.NET,另一种是利用Oracle提供的ODP.NET. 安装VS的时候会附带ADO.NET,安装Oracl ...
 - Sublime 2 Installation for Linux
			
Linux You can download the package and uncompress it manually. Alternatively, you can use the comman ...
 - 关于Cookie和Session【转载】
			
当你第一次访问一个网站的时候,网站服务器会在响应头内加上Set-Cookie:PHPSESSID=nj1tvkclp3jh83olcn3191sjq3(php服务器),或Set-Cookie JSES ...
 - Java8 时间 API
			
前言 Java8 中最为人津津乐道的新改变恐怕当属函数式 API 的加入.但实际上,Java8 所加入的新功能远不止这个. 本文将基于<Java SE8 for the Really Impat ...
 - Hadoop2以来的历次升级(不含2.2.0及以下)
			
2015年7月06:release 2.7.1(稳定)请参阅 Hadoop 2.7.1发布说明 对131个bug修复和列表 从先前版本2.7.0补丁. 请看看 2.7.0章节列表的增强功能启用 第一个 ...
 - HDU 3016 Man Down (线段树+dp)
			
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...