要求为个人银行存款帐户定义一个类Custom,该类包含“帐户名”、“余额”等二个属性。以Custom类为父类创建两个子类:一个是活期存款帐户CheckingCustom类,另一个是定期存款帐户FixedCustom类;每个子类中包含一个“帐号”属性。所有属性均定义为私有属性。
求代码。Visual
Studio 2010构造。
1. 创建活期帐户时,必须提供帐户名和开户金额,而帐号则根据存款分类自动生成。
2. 活期存款帐号的范围为10001~19999,活期存款的利息当前余额的0.5%计算。每次取款时,不论存款时间多长,都要先根据当前余额结算一次利息,并将利息复加到现有余额中,然后再从中取出指定的款数。存款时不计算利息。
3. 定期存款帐号的范围为20001~29999,定期存款的利息计算方法如下:如果当前余额大于500,利息为3%,否则利息为2%。毎次取款时,不论存款时间多长,都要先根据当前余额结算一次利息,并将利息复加到现有余额中,然后再从中取出指定的款数。存款时不计算利息。
模拟银行存取款业务 c# Visual Studio 2010构造。
答案:3 悬赏:70 手机版
解决时间 2021-03-05 07:57
- 提问者网友:溺爱和你
- 2021-03-05 02:22
最佳答案
- 五星知识达人网友:撞了怀
- 2021-03-05 03:33
///
/// 银行类
///
public class Custom
{
private string zhm;
private double ye;
///
/// 帐户名
///
public string ZHM
{
get { return zhm; }
set { this.zhm = value; }
}
///
/// 余额
///
public double YE
{
get { return ye; }
set { this.ye=value;}
}
///
/// 有参构造
///
/// 账户名
/// 余额
public Custom(string zhm,double ye)
{
this.ZHM = zhm;
this.YE = ye;
}
///
/// 虚方法
///
///
public virtual string zh()
{
return "";
}
///
/// 添加数据
///
///
public virtual bool addsj()
{
return true;
}
}
///
/// 活期帐户
///
public class CheckingCustom:Custom
{
private string kh;
public CheckingCustom(string zhm, double ye)
: base(zhm, ye)
{
}
///
/// 返回活期帐户 的卡号
///
///
public override string zh()
{
Random rd = new Random();
kh=rd.Next(10001, 19999).ToString();
return string.Format("活期帐户 \r\n 卡号{0}\r\n 帐号名{1} \r\n 余额{2}", kh, ZHM, YE);
}
///
/// 添加数据
///
///
public override bool addsj()
{
return tjsj.addsj(kh, ZHM, YE, 0); ;
}
}
///
///定期存款
///
public class FixedCustom : Custom
{
private string fkh;
public FixedCustom(string zhm, double ye)
: base(zhm, ye)
{
}
///
/// 返回定期存款的卡号
///
///
public override string zh()
{
Random rd = new Random();
fkh = rd.Next(20001, 29999).ToString();
return string.Format("定期存款 \r\n 卡号{0}\r\n 帐号名{1} \r\n 余额{2}",fkh,ZHM,YE);
}
public override bool addsj()
{
return tjsj.addsj(fkh, ZHM, YE, 1); ;
}
}
public class tjsj
{
///
/// 添加存款信息
///
///
///
///
///
///
public static bool addsj(string kh,string zhm,double ye,int ishq)
{
string sql = @"insert into yhk(kh,zhm,ye,ishq)
values('" + kh + "','"+zhm+"',"+ye+","+ishq+")";
return DbHlper.ExecuteNonQuery(sql, CommandType.Text);
}
///
/// 返回所有的存款
///
///
public static DataSet fhsj()
{
string sql = "select * from yhk";
return DbHlper.OutDataSet(sql, CommandType.Text);
}
///
/// 返回id 的存款
///
///
///
public static string[] fhsj(string id)
{
string sql = "select * from yhk where id="+id;
string[] st=new string[5];
for (int i = 0; i < 5; i++)
{
st[i]=string.Empty;
}
using (SqlDataReader sdr=DbHlper.ExecuteReader(sql,CommandType.Text) )
{
while (sdr.Read())
{
st[0] = sdr["id"].ToString();
st[1] = sdr["kh"].ToString();
st[2] = sdr["zhm"].ToString();
st[3] = sdr["ye"].ToString();
st[4] = sdr["ishq"].ToString();
}
}
return st;
}
///
/// 修正余额
///
///
///
///
public static bool upyhk(string id,double ye)
{
string sql = "update yhk set ye="+ye+" where id=1";
return DbHlper.ExecuteNonQuery(sql,CommandType.Text);
}
}
Custom cu;
string zhm = txtzhm.Text; double ye = Convert.ToDouble(txtye.Text);
if (radioButtonhq.Checked)
{//活期
cu = new CheckingCustom(zhm, ye);
}
else
{//定期
cu = new FixedCustom(zhm, ye);
}
DialogResult dr = MessageBox.Show(cu.zh(), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (DialogResult.Yes == dr)
{
cu.addsj();
this.Close();
}
private void btnqd_Click(object sender, EventArgs e)
{
if (txtqkje.Text.Length==0)
{
MessageBox.Show("取款余额不能为空");
return;
}
double i;
try
{
i = Convert.ToDouble(txtqkje.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
double b = Convert.ToDouble(textBoxye.Text);
if(i>b)
{
MessageBox.Show("取款金额不能大于金额");
return;
}
double d=0;
double f=0;
if (radioButtonhq.Checked)
{//活期
d = (b * 0.0005) + b;
f = d - i;
}
else
{//定期
if (b > 500)
{
d = (b * 0.003) + b;
f = d - i;
}
else
{
d = (b * 0.002) + b;
f = d - i;
}
}
DialogResult dr=MessageBox.Show(string.Format("金额为{0}\r\n取款为{1}\r\n余额为{2}",b,i,f),
"提示",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
if (DialogResult.Yes == dr)
{//yes 时
tjsj.upyhk(id, f);
this.Close();//关闭
}
}
请给分
/// 银行类
///
public class Custom
{
private string zhm;
private double ye;
///
/// 帐户名
///
public string ZHM
{
get { return zhm; }
set { this.zhm = value; }
}
///
/// 余额
///
public double YE
{
get { return ye; }
set { this.ye=value;}
}
///
/// 有参构造
///
/// 账户名
/// 余额
public Custom(string zhm,double ye)
{
this.ZHM = zhm;
this.YE = ye;
}
///
/// 虚方法
///
///
public virtual string zh()
{
return "";
}
///
/// 添加数据
///
///
public virtual bool addsj()
{
return true;
}
}
///
/// 活期帐户
///
public class CheckingCustom:Custom
{
private string kh;
public CheckingCustom(string zhm, double ye)
: base(zhm, ye)
{
}
///
/// 返回活期帐户 的卡号
///
///
public override string zh()
{
Random rd = new Random();
kh=rd.Next(10001, 19999).ToString();
return string.Format("活期帐户 \r\n 卡号{0}\r\n 帐号名{1} \r\n 余额{2}", kh, ZHM, YE);
}
///
/// 添加数据
///
///
public override bool addsj()
{
return tjsj.addsj(kh, ZHM, YE, 0); ;
}
}
///
///定期存款
///
public class FixedCustom : Custom
{
private string fkh;
public FixedCustom(string zhm, double ye)
: base(zhm, ye)
{
}
///
/// 返回定期存款的卡号
///
///
public override string zh()
{
Random rd = new Random();
fkh = rd.Next(20001, 29999).ToString();
return string.Format("定期存款 \r\n 卡号{0}\r\n 帐号名{1} \r\n 余额{2}",fkh,ZHM,YE);
}
public override bool addsj()
{
return tjsj.addsj(fkh, ZHM, YE, 1); ;
}
}
public class tjsj
{
///
/// 添加存款信息
///
///
///
///
///
///
public static bool addsj(string kh,string zhm,double ye,int ishq)
{
string sql = @"insert into yhk(kh,zhm,ye,ishq)
values('" + kh + "','"+zhm+"',"+ye+","+ishq+")";
return DbHlper.ExecuteNonQuery(sql, CommandType.Text);
}
///
/// 返回所有的存款
///
///
public static DataSet fhsj()
{
string sql = "select * from yhk";
return DbHlper.OutDataSet(sql, CommandType.Text);
}
///
/// 返回id 的存款
///
///
///
public static string[] fhsj(string id)
{
string sql = "select * from yhk where id="+id;
string[] st=new string[5];
for (int i = 0; i < 5; i++)
{
st[i]=string.Empty;
}
using (SqlDataReader sdr=DbHlper.ExecuteReader(sql,CommandType.Text) )
{
while (sdr.Read())
{
st[0] = sdr["id"].ToString();
st[1] = sdr["kh"].ToString();
st[2] = sdr["zhm"].ToString();
st[3] = sdr["ye"].ToString();
st[4] = sdr["ishq"].ToString();
}
}
return st;
}
///
/// 修正余额
///
///
///
///
public static bool upyhk(string id,double ye)
{
string sql = "update yhk set ye="+ye+" where id=1";
return DbHlper.ExecuteNonQuery(sql,CommandType.Text);
}
}
Custom cu;
string zhm = txtzhm.Text; double ye = Convert.ToDouble(txtye.Text);
if (radioButtonhq.Checked)
{//活期
cu = new CheckingCustom(zhm, ye);
}
else
{//定期
cu = new FixedCustom(zhm, ye);
}
DialogResult dr = MessageBox.Show(cu.zh(), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (DialogResult.Yes == dr)
{
cu.addsj();
this.Close();
}
private void btnqd_Click(object sender, EventArgs e)
{
if (txtqkje.Text.Length==0)
{
MessageBox.Show("取款余额不能为空");
return;
}
double i;
try
{
i = Convert.ToDouble(txtqkje.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
double b = Convert.ToDouble(textBoxye.Text);
if(i>b)
{
MessageBox.Show("取款金额不能大于金额");
return;
}
double d=0;
double f=0;
if (radioButtonhq.Checked)
{//活期
d = (b * 0.0005) + b;
f = d - i;
}
else
{//定期
if (b > 500)
{
d = (b * 0.003) + b;
f = d - i;
}
else
{
d = (b * 0.002) + b;
f = d - i;
}
}
DialogResult dr=MessageBox.Show(string.Format("金额为{0}\r\n取款为{1}\r\n余额为{2}",b,i,f),
"提示",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
if (DialogResult.Yes == dr)
{//yes 时
tjsj.upyhk(id, f);
this.Close();//关闭
}
}
请给分
全部回答
- 1楼网友:冷風如刀
- 2021-03-05 05:05
1)visual c#:微软新一代编程语言,类似java,面向对象程序设计而特意制作。
c++:扩展了原有的c++6.0版本,使之可以与net无缝集成,也可以单独开发纯c++非托管的程序。
根据你需要决定。你如果学习c++,装后者;否则前者。
2)安装2010之后,vb6可以保留。因为vb.net和vb6差别很大了。几乎没有什么联系(除了语法之外)。
- 2楼网友:白昼之月
- 2021-03-05 03:50
怎么感谢 ,,这个
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯