日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

集存款(复利单利)贷款为一体的计算器(最新版)

發(fā)布時間:2024/4/14 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 集存款(复利单利)贷款为一体的计算器(最新版) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

事先說明:由于篇幅有限,只展示部分代碼和運行結果。

?

?

?

這段小代碼是屬于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 exceptionJOptionPane.showMessageDialog(null, "數據輸入有誤,請重新輸入數字");}principal = 0;while (year <= n) {principal = amount / (Math.pow(1 + rate, year));year = year + 1;}output = "本金" + currencyformatter.format(principal) + "\n";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 exceptionJOptionPane.showMessageDialog(null, "數據輸入有誤,請重新輸入數字");}rate = java.lang.StrictMath.pow(amount / principal, 1.0 / n) - 1;output = "利率" + rate + "\n";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 exceptionJOptionPane.showMessageDialog(null, "數據輸入有誤,請重新輸入數字");}double year2=Math.log(amount/principal)/Math.log(1+rate);output = "至少年數" + year2 + "\n";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 exceptionJOptionPane.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) + "\t\t\t"+ currencyformatter.format(amount) + "\n";year = year + 1;}} else {while (year <= n) {amount = principal * Math.pow(1 + rate, year);output += String.valueOf(year) + "\t\t\t"+ currencyformatter.format(amount) + "\n";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 exceptionJOptionPane.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);}}

  

?

?

這個是登錄界面:

?

?

這個是存款界面

?

?

?

這個是貸款主界面:

?

?

?

?

這兩張是非法性輸入處理:

?

?

?

?

這個是貸款運行演示:

?

?

?

?

總結:軟件工程決定了軟件的質量,一開始一旦設計不合理,后面需要花很長時間進行維護。比起實現功能,邏輯設計更加難

?

如需要源代碼請聯(lián)系QQ694335719或者微信lin694335719,也可上github下載瀏覽,僅做交流學習用途

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

如果可以,我希望能開發(fā)投資功能,提供最佳投資方案

?

轉載于:https://www.cnblogs.com/15linzhijie/p/5299290.html

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的集存款(复利单利)贷款为一体的计算器(最新版)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。