Java编程:建立一个银行账户类BankAccount
该类数据成员包括:(1)户名m_iName(2)账户金额m_dBalance(3)年利率m_dInterestRate该类的成员函数包括:(1)构造函数BankAccou...
该类数据成员包括:(1)户名m_iName(2)账户金额m_dBalance(3)年利率m_dInterestRate
该类的成员函数包括:(1)构造函数BankAccount,设置户名、账户金额、利率的初始值,构造函数重载;(2)函数getBalance,获取账户金额;(3)函数getInterestRate,获取当前利率;(4)函数setInterestRate,设置当前利率;(5)函数printAccountMsg,打印当前账户信息;(6)函数saveMoney,存款操作;(7)函数getMoney,取款操作;(8)函数caculateInterest(int Days)按当前利率当前存款计算给定天数的净利息。
建应用程序类ExampleAccount,在应用函数类的main函数中完成以下操作(1)建一个BankAccount类的对象;(2)打印账户信息;(3)存入一笔钱;(4)打印账户信息;(5)取出一笔钱;(6)打印账户信息;(7)计算十年后的银行存款额并打印;(8)改变利率后计算十年后的银行存款额并打印。 展开
该类的成员函数包括:(1)构造函数BankAccount,设置户名、账户金额、利率的初始值,构造函数重载;(2)函数getBalance,获取账户金额;(3)函数getInterestRate,获取当前利率;(4)函数setInterestRate,设置当前利率;(5)函数printAccountMsg,打印当前账户信息;(6)函数saveMoney,存款操作;(7)函数getMoney,取款操作;(8)函数caculateInterest(int Days)按当前利率当前存款计算给定天数的净利息。
建应用程序类ExampleAccount,在应用函数类的main函数中完成以下操作(1)建一个BankAccount类的对象;(2)打印账户信息;(3)存入一笔钱;(4)打印账户信息;(5)取出一笔钱;(6)打印账户信息;(7)计算十年后的银行存款额并打印;(8)改变利率后计算十年后的银行存款额并打印。 展开
展开全部
public class BankAccount {
private String m_iName;
private double m_dBalance;
private double m_dInterestRate;
public BankAccount(){
m_iName="";
m_dBalance=0.0;
m_dInterestRate=0.0;
}
public BankAccount(String name, double balance, double interestRate) {
m_iName = name;
m_dBalance = balance;
m_dInterestRate = interestRate;
}
public String getM_iName() {
return m_iName;
}
public void setM_iName(String name) {
m_iName = name;
}
public double getBalance() {
return m_dBalance;
}
public void setM_dBalance(double balance) {
m_dBalance = balance;
}
public double getInterestRate() {
return m_dInterestRate;
}
public void setInterestRate(double interestRate) {
m_dInterestRate = interestRate;
}
public void printAccountMsg(){
System.out.println("帐户:"+m_iName+" 当前余额"+m_dBalance+"元 年利率毕宴为"+m_dInterestRate*100+"%");
}
public void saveMoney(double money){
m_dBalance+=money;
}
public void getMoney(double money){
if(money<=m_dBalance)
m_dBalance-=money;
else
System.out.println("对不起,您的帐余额不足!");
}
public double caculateInterest(int Days){
return m_dBalance*m_dInterestRate*Days/携亩365;
}
}
public class ExampleAccount {
public static void main(String[] args) {
BankAccount ba = new BankAccount("Andy",88888,0.01);
ba.printAccountMsg();
ba.saveMoney(1000);
ba.printAccountMsg();
ba.getMoney(10000);
ba.printAccountMsg();
System.out.println("当前利手隐银率为"+ba.getInterestRate()+" 十年后帐户余额将是:"+(ba.getBalance()+ba.caculateInterest(365*10))+"元。");
ba.setInterestRate(0.02);
System.out.println("若利率为"+ba.getInterestRate()+" 十年后帐户余额将是"+(ba.getBalance()+ba.caculateInterest(365*10))+"元。");
}
}
private String m_iName;
private double m_dBalance;
private double m_dInterestRate;
public BankAccount(){
m_iName="";
m_dBalance=0.0;
m_dInterestRate=0.0;
}
public BankAccount(String name, double balance, double interestRate) {
m_iName = name;
m_dBalance = balance;
m_dInterestRate = interestRate;
}
public String getM_iName() {
return m_iName;
}
public void setM_iName(String name) {
m_iName = name;
}
public double getBalance() {
return m_dBalance;
}
public void setM_dBalance(double balance) {
m_dBalance = balance;
}
public double getInterestRate() {
return m_dInterestRate;
}
public void setInterestRate(double interestRate) {
m_dInterestRate = interestRate;
}
public void printAccountMsg(){
System.out.println("帐户:"+m_iName+" 当前余额"+m_dBalance+"元 年利率毕宴为"+m_dInterestRate*100+"%");
}
public void saveMoney(double money){
m_dBalance+=money;
}
public void getMoney(double money){
if(money<=m_dBalance)
m_dBalance-=money;
else
System.out.println("对不起,您的帐余额不足!");
}
public double caculateInterest(int Days){
return m_dBalance*m_dInterestRate*Days/携亩365;
}
}
public class ExampleAccount {
public static void main(String[] args) {
BankAccount ba = new BankAccount("Andy",88888,0.01);
ba.printAccountMsg();
ba.saveMoney(1000);
ba.printAccountMsg();
ba.getMoney(10000);
ba.printAccountMsg();
System.out.println("当前利手隐银率为"+ba.getInterestRate()+" 十年后帐户余额将是:"+(ba.getBalance()+ba.caculateInterest(365*10))+"元。");
ba.setInterestRate(0.02);
System.out.println("若利率为"+ba.getInterestRate()+" 十年后帐户余额将是"+(ba.getBalance()+ba.caculateInterest(365*10))+"元。");
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询