集存款(复利单利)贷款为一体的计算器(最新版)-ag真人官方网址

大家好!今天让小编来大家介绍下关于集存款(复利单利)贷款为一体的计算器(最新版)的问题,以下是酷知号的小编对此问题的归纳整理,让我们一起来看看吧。

事先说明:由于篇幅有限,只展示部分代码和运行结果。

这段小代码是属于fuli类的,使用try catch包围及使用if语句防止非法输入

private class c1actioneventhander implements actionlistener {
        public void actionperformed(actionevent e) {
            double principal = 0;
            double amount = 0;
            double rate = 0;
            int n = 0;
            numberformat currencyformatter = numberformat.getcurrencyinstance(); // 字符串转化为数字
            string output = "年"   "/"   "复利存款";
            int year = 1;
            int result;
            if (b1.gettext().equals("") && b2.gettext() != null
                    && b3.gettext() != null && b4.gettext() != null) {
                try {
                    rate = double.parsedouble(b2.gettext());
                    if(rate<0){
                        joptionpane.showmessagedialog(null, "利率输入有误,请重新输入数字");
                        rate=0;
                    }
                    n = integer.parseint(b3.gettext());
                    if(n<0){
                        joptionpane.showmessagedialog(null, "年份输入有误,请重新输入数字");
                        n=0;
                    }
                    amount = double.parsedouble(b4.gettext());
                    if(amount<0){
                        joptionpane.showmessagedialog(null, "期待值输入有误,请重新输入数字");
                        amount=0;
                    }
                } catch (exception e2) {
                    // todo: handle exception
                    joptionpane.showmessagedialog(null, "数据输入有误,请重新输入数字");
                }
                principal = 0;
                while (year <= n) {
                    principal = amount / (math.pow(1   rate, year));
                    year = year   1;
                }
                output = "本金"   currencyformatter.format(principal)   "
";
                text.settext(output);
            }
            else if (b2.gettext().equals("") && b1.gettext() != null
                    && b3.gettext() != null && b4.gettext() != null) // 求利率
            {
                try {
                    principal = double.parsedouble(b1.gettext()); // b1本金
                    if(principal<0){
                        joptionpane.showmessagedialog(null, "本金输入有误,请重新输入数字");
                        principal=0;
                    }
                    n = integer.parseint(b3.gettext()); // b3年份
                    if(n<0){
                        joptionpane.showmessagedialog(null, "年份输入有误,请重新输入数字");
                        n=0;
                    }
                    amount = double.parsedouble(b4.gettext()); // b4期望值
                    if(amount<0){
                        joptionpane.showmessagedialog(null, "期待值输入有误,请重新输入数字");
                        amount=0;
                    }
                } catch (exception e2) {
                    // todo: handle exception
                    joptionpane.showmessagedialog(null, "数据输入有误,请重新输入数字");
                }
                rate = java.lang.strictmath.pow(amount / principal, 1.0 / n) - 1;
                output = "利率"   rate   "
";
                text.settext(output);
            }
            else if (b3.gettext().equals("") && b1.gettext() != null
                    && b2.gettext() != null && b4.gettext() != null) // 求年份
            {
                try {
                    principal = double.parsedouble(b1.gettext()); // b1本金
                    if(principal<0){
                        joptionpane.showmessagedialog(null, "本金输入有误,请重新输入数字");
                        principal=0;
                    }
                    amount = double.parsedouble(b4.gettext()); // b4期望值
                    if(amount<0){
                        joptionpane.showmessagedialog(null, "期待值输入有误,请重新输入数字");
                        amount=0;
                    }
                    rate = double.parsedouble(b2.gettext());
                    if(rate<0){
                        joptionpane.showmessagedialog(null, "利率输入有误,请重新输入数字");
                        rate=0;
                    }
                } catch (exception e2) {
                    // todo: handle exception
                    joptionpane.showmessagedialog(null, "数据输入有误,请重新输入数字");
                }
        
                double year2=math.log(amount/principal)/math.log(1 rate);
                output = "至少年数"   year2   "
";
                text.settext(output);
            }
            else if (b4.gettext().equals("") && b1.gettext() != null
                    && b3.gettext() != null && b2.gettext() != null) // 求期望值
            {
                try {
                    rate = double.parsedouble(b2.gettext());
                    if(rate<0){
                        joptionpane.showmessagedialog(null, "利率输入有误,请重新输入数字");
                        rate=0;
                    }
                    n = integer.parseint(b3.gettext());
                    if(n<0){
                        joptionpane.showmessagedialog(null, "年份输入有误,请重新输入数字");
                        n=0;
                    }
                    principal = double.parsedouble(b1.gettext()); // b1本金
                    if(principal<0){
                        joptionpane.showmessagedialog(null, "本金输入有误,请重新输入数字");
                        rate=0;
                    }
                } catch (exception e2) {
                    // todo: handle exception
                    joptionpane.showmessagedialog(null, "数据输入有误,请重新输入数字");
                }
                double tempprincipal = principal;
                result = joptionpane.showconfirmdialog(null, "是否每年添加本金");
                if (result == joptionpane.yes_option) {
                    while (year <= n) {
                        amount = principal * math.pow(1   rate, year)
                                  tempprincipal;
                        output  = string.valueof(year)   "			"
                                  currencyformatter.format(amount)   "
";
                        year = year   1;
                    }
                } else {
                    while (year <= n) {
                        amount = principal * math.pow(1   rate, year);
                        output  = string.valueof(year)   "			"
                                  currencyformatter.format(amount)   "
";
                        year = year   1;
                    }
                }
                text.settext(output);
            } else if (b1.gettext() != null && b4.gettext() != null
                    && b3.gettext() != null && b2.gettext() != null) {
                joptionpane.showmessagedialog(null, "请删除一个数据");
            } else {
                joptionpane.showmessagedialog(null, "请增加数据");
            }
        }
    }

这段代码是登录界面代码

	private class myitemlistener implements actionlistener//处理事件
		{
			 public void actionperformed(actionevent e){  
			object bj = e.getsource(); // 获得事件源
			if (bj == deposit) { // 若是鼠标点击开始游戏按钮,则调用mainclass()函数进入游戏
				new fuli();
			} else if (bj == exit) // 若是点击结束按钮,则退出登录界面
				system.exit(0);
			else if(bj==credit){
				new credit();
			}
		}
	}

这部分是计算分期还贷款的代码

private class c1actioneventhander implements actionlistener {
		public void actionperformed(actionevent e) {
			string output = null;
			double principle=0;
			double rate=0;
			double time=0;
			double money=0;
			try {
				principle=double.parsedouble(b1.gettext());
				if(principle<0){
					joptionpane.showmessagedialog(null, "输入的贷款金额有误,请重新输入");
					principle=0;
				}
				rate=double.parsedouble(b2.gettext());
				if(rate<0){
					joptionpane.showmessagedialog(null, "输入的贷款利率有误,请重新输入");
					rate=0;
				}
				time=double.parsedouble(b3.gettext());
				if(time<0){
					joptionpane.showmessagedialog(null, "输入的还款期限有误,请重新输入");
					time=0;
				}
			} catch (exception e2) {
				// todo: handle exception
				joptionpane.showmessagedialog(null, "数据输入有误,请重新输入");
			}
			
		
			calculjbbutton();
			money=principle*rate*time principle;
			double money2=money;
			double data=12/jbbutton*time;
			money=money/data;
			output="本息:" money2 "     每" jbbutton "个月需要付" money "元";
			d1.settext(output);
		}
	}

这个是登录界面:

这个是存款界面

这个是贷款主界面:

这两张是非法性输入处理:

这个是贷款运行演示:

总结:软件工程决定了软件的质量,一开始一旦设计不合理,后面需要花很长时间进行维护。比起实现功能,逻辑设计更加难

如需要源代码请联系qq694335719或者微信lin694335719,也可上github下载浏览,仅做交流学习用途

github地址:https://github.com/hellolaona/text

如果可以,我希望能开发投资功能,提供最佳投资方案

以上就是小编对于集存款(复利单利)贷款为一体的计算器(最新版)问题和相关问题的解答了,集存款(复利单利)贷款为一体的计算器(最新版)的问题希望对你有用!

© ag真人官方网址的版权声明
the end
喜欢就支持一下吧
分享