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 ...
随机推荐
- springmvc 参数绑定
1. httpservletrequest request request.getParameter("a")方法去取参数 用注解@RequestParam绑定请求参数 用注解@R ...
- UOJ 217 奇怪的线段树
http://uoj.ac/problem/217 题意就不X了,思路在这: 居然一开始把sap里面的mn设置为inf了,我是傻逼.. #include<cstdio> #include& ...
- 利用Tree命令生成磁盘文件列表
命令原型:D:/>tree /? 以图形显示驱动器或路径的文件夹结构.TREE [drive:][path] [/F] [/A]/F 显示每个文件夹中文件的名称./A 使用 ASCII 字符,而 ...
- 为什么 O2O 领域融资额特别高?
在36氪搜索“o2o”,融资额基本都是数千万乃至数亿,为什么这个领域的创业项目融资额如此之高?融到的钱一般用在什么地方? --------------------------------------- ...
- Local System、Local Service與Network Service
CreateService参数介绍SC_HANDLE CreateService( SC_HANDLE hSCManager, //服务控制管理程序维护的登记数据库的句柄,由系统函数OpenSCMan ...
- 【HDOJ】2395 Alarm Clock
水题. /* 2395 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...
- Facebook 开源 AI 所使用的硬件平台 'Big Sur'
Facebook 开源 AI 所使用的硬件平台 'Big Sur' Facebook 今开源其 AI 所使用的硬件平台 'Big Sur'.'Big Sur' 是兼容开放机架的 GPU 加速硬件平台. ...
- 【模拟】HDU 5752 Sqrt Bo
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 题目大意: 定义f(n)=⌊√n⌋,fy(n)=f(fy-1(n)),求y使得fy(n)=1. ...
- C++編程札記「基礎」
一直以為自己最擅長的編程語言是C++,那時自己的水平停留在使用C++來實現數據結構中的各種ADT和ACM算法. 創建一個類,必須實現的成員函數 explicit構造函數 對於單參數構造函數,添加exp ...
- java排序算法-归并排序
public class MergeSort { private static void mergeSortTest() { int[] in = { 2, 5, 3, 8, 6, 7, 1, 4, ...