复利计算器4-程序员宅基地

技术标签: java  

  1 import java.awt.Color;
  2 import java.awt.Container;
  3 import java.awt.Dimension;
  4 import java.awt.FlowLayout;
  5 import java.awt.Font;
  6 import java.awt.Graphics;
  7 import java.awt.GridLayout;
  8 import java.awt.Image;
  9 import java.awt.Toolkit;
 10 import java.awt.event.ActionEvent;
 11 import java.awt.event.ActionListener;
 12 import java.text.NumberFormat;
 13 
 14 import javax.swing.ImageIcon;
 15 import javax.swing.JButton;
 16 import javax.swing.JFrame;
 17 import javax.swing.JLabel;
 18 import javax.swing.JOptionPane;
 19 import javax.swing.JPanel;
 20 import javax.swing.JScrollPane;
 21 import javax.swing.JTextArea;
 22 import javax.swing.JTextField;
 23 import javax.swing.border.LineBorder;
 24 
 25 public class Fuli2  extends JFrame
 26 {
 27     private JLabel a1;
 28     private JLabel a2;
 29     private JLabel a3;
 30     private JLabel a4;
 31     private JLabel a5;
 32     private JTextField b1;
 33     private JTextField b2;
 34     private JTextField b3;
 35     private JTextField b4;
 36     private JTextField b5;
 37     private JButton c1;
 38     private JButton c2;
 39     private JButton c3;
 40     private JButton c4;
 41     private JButton c5;
 42     private JButton c6;
 43     private JTextArea text;
 44     public Fuli2()
 45     {
 46         creatComponents()    ;
 47         layoutComponents();
 48         registerHandlers();
 49         setTitle("存款应用程序");
 50         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 51         pack();
 52     }
 53     private void  creatComponents()    
 54     {
 55         a1=new JLabel("本  金 ");
 56         a1.setFont(new Font("宋体",Font.BOLD,18));
 57         a2=new JLabel("年利率 ");
 58         a2.setFont(new Font("宋体",Font.BOLD,18));
 59         a3=new JLabel("年 数 ");
 60         a3.setFont(new Font("宋体",Font.BOLD,18));
 61         a4=new JLabel("本息 ");
 62         a4.setFont(new Font("宋体",Font.BOLD,18));
 63         a5=new JLabel("月利率 ");
 64         a5.setFont(new Font("宋体",Font.BOLD,18));
 65         
 66         
 67         
 68         b1=new JTextField(10);//本金
 69         b2=new JTextField(10);//利率
 70         b3=new JTextField(10);//年数
 71         b4=new JTextField(10);//本息
 72         b5=new JTextField(10);//月利率
 73         c1=new JButton("复利");
 74         c1.setFont(new Font("宋体",Font.BOLD,15));
 75         c3=new JButton("单利");
 76         c3.setFont(new Font("宋体",Font.BOLD,15));
 77         c4=new JButton("定投");
 78         c4.setFont(new Font("宋体",Font.BOLD,15));
 79         c2=new JButton("清除");
 80         c2.setFont(new Font("宋体",Font.BOLD,15));
 81         c5=new JButton("复利存期/利率");
 82         c5.setFont(new Font("宋体",Font.BOLD,15));
 83         c6=new JButton("等额还款");
 84         c6.setFont(new Font("宋体",Font.BOLD,15));
 85         text=new JTextArea();
 86     }
 87     private void layoutComponents()
 88     {
 89         //Container c=this.getContentPane();    
 90         setLayout(new FlowLayout());
 91         JPanel panel1=new JPanel();
 92         panel1.add(a1);
 93         panel1.add(b1);
 94         
 95         JPanel panel2=new JPanel();
 96         panel2.add(a2);
 97         panel2.add(b2);
 98         panel2.add(a5);
 99         panel2.add(b5);
100         
101         JPanel panel3=new JPanel();
102         panel3.add(a3);
103         panel3.add(b3);
104         JPanel panel4=new JPanel();
105         panel4.add(a4);
106         panel4.add(b4);
107         
108         JPanel panel5=new JPanel();
109         panel5.add(c1);
110         panel5.add(c3);
111         panel5.add(c4);
112         panel5.add(c5);
113         panel5.add(c2);
114         panel5.add(c6);
115         JPanel  leftpanel=new JPanel(new GridLayout(6,2));
116         leftpanel.add(panel1);
117         leftpanel.add(panel2);
118         leftpanel.add(panel3);
119         leftpanel.add(panel4);
120         leftpanel.add(panel5);
121         JScrollPane panel6=new JScrollPane(text);
122         panel6.setPreferredSize(new Dimension(250,100));
123         add(leftpanel);
124         add(panel6);
125     }
126     private  void registerHandlers()
127     {
128          c1ActionEventHander hander1=new  c1ActionEventHander();
129          c1.addActionListener(hander1);
130          c2ActionEventHander hander2=new  c2ActionEventHander();
131          c2.addActionListener(hander2);
132     c3ActionEventHander hander3=new  c3ActionEventHander();
133         c3.addActionListener(hander3);
134         c4ActionEventHander hander4=new  c4ActionEventHander();
135         c4.addActionListener(hander4);
136         c5ActionEventHander hander5=new  c5ActionEventHander();
137         c5.addActionListener(hander5);
138         c6ActionEventHander hander6=new  c6ActionEventHander();
139         c6.addActionListener(hander6);
140     }
141     private class c1ActionEventHander implements ActionListener
142     {
143         public void actionPerformed(ActionEvent e)
144         {
145             double principal;
146             double amount;
147             double rate;
148             int n;
149             NumberFormat currencyformatter=NumberFormat.getCurrencyInstance();
150             String output="年"+"/t"+"复利存款"+"/n";
151              double year =1;
152            //  principal=Double.parseDouble(b1.getText());
153              rate=Double.parseDouble(b2.getText()); 
154              n=Integer.parseInt(b3.getText());
155              if(b1.getText().equals(""))//本金
156              {
157                  if (b4.getText().equals(""))
158                  {
159                      JOptionPane.showMessageDialog(null, "请输入本金或者本息");
160                 
161                  }
162                  else{
163                 amount = Double.parseDouble(b4.getText());
164                 principal=0;
165                 while (year <= n) {
166                     principal=amount/(Math.pow(1 + rate, year));
167                     year = year + 1;
168                 }
169                 
170                 output="本金"+currencyformatter.format(principal) + "\n";
171                 text.setText(output);
172             }
173         }
174         else {
    //本息
175             principal = Double.parseDouble(b1.getText()); // 字符串转化为数字
176             
177             if (b4.getText().equals("")) {
178                 while (year <= n) {
179                     amount = principal * Math.pow(1 + rate, year);
180                     output += String.valueOf(year) + "\t"+ currencyformatter.format(amount) + "\n";
181                     year = year + 1;
182                 }
183 
184                 text.setText(output);
185                 
186             }
187             else{
188                 JOptionPane.showMessageDialog(null, "本金和本息输入一个即可");
189             }
190         }
191         }
192 
193 }
194     private class  c2ActionEventHander implements ActionListener
195     {
196         public void actionPerformed(ActionEvent e)
197         {
198             b1.setText("");
199             b2.setText("");
200             b3.setText("");
201             b4.setText("");
202             text.setText("");
203         }
204     }
205     private class c3ActionEventHander implements ActionListener {
206         public void actionPerformed(ActionEvent e) {
207             double principal;
208             double amount;
209             double rate;
210             int n;
211             NumberFormat currencyformatter = NumberFormat.getCurrencyInstance();
212             String output = "年" + "/" + "单利存款";
213             int year = 1;
214             
215             rate = Double.parseDouble(b2.getText());
216             n = Integer.parseInt(b3.getText());
217             if(b1.getText().equals(""))
218             {
219                 if (b4.getText().equals(""))
220                 {
221                     JOptionPane.showMessageDialog(null, "请输入本金或者本息");
222                     
223                 }
224                 else{
225                     amount = Double.parseDouble(b4.getText());
226                     principal=0;
227                     while (year <= n) {
228                         principal = amount / (1 + rate* year);
229                         year = year + 1;
230                     }
231                     
232                     output="本金"+currencyformatter.format(principal) + "\n";
233                     text.setText(output);
234                 }
235             }
236             else {
237                 principal = Double.parseDouble(b1.getText()); // 字符串转化为数字
238                 
239                 if (b4.getText().equals("")) {
240                     while (year <= n) {
241                         amount = principal * (1 + rate* year);
242                         output += String.valueOf(year) + "\t"
243                                 + currencyformatter.format(amount) + "\n";
244                         year = year + 1;
245                     }
246     
247                     text.setText(output);
248                     }
249                 else{
250                     JOptionPane.showMessageDialog(null, "本金和本息输入一个即可");
251                 }
252             }
253             
254         }
255     }
256     private class c4ActionEventHander implements ActionListener
257     {
258     public void actionPerformed(ActionEvent e)
259     {
260          double principal;
261          double amount;
262          double rate;
263          int n;
264          NumberFormat currencyformatter=NumberFormat.getCurrencyInstance();
265          String output="年"+"/t"+"复利存款"+"/n";
266           double year =1;
267         //  principal=Double.parseDouble(b1.getText());
268           rate=Double.parseDouble(b2.getText()); 
269           n=Integer.parseInt(b3.getText());
270           principal = Double.parseDouble(b1.getText()); // 字符串转化为数字
271           
272           if (b4.getText().equals("")) {
273               while (year <= n) {
274                   amount = principal*(Math.pow(1+ rate, year+1)-1)/rate;
275                   output += String.valueOf(year) + "\t"+ currencyformatter.format(amount) + "\n";
276                   year = year + 1;
277               }
278 
279               text.setText(output);
280               
281           }
282           else{
283               JOptionPane.showMessageDialog(null, "请输入每年定投的金额");
284           }
285         
286     }
287     }
288     private class c5ActionEventHander implements ActionListener//计算年份和利率
289     {
290         public void actionPerformed(ActionEvent e)
291         {
292             double amount;
293             double rate;
294             double principal;
295             String output;
296              NumberFormat currencyformatter = NumberFormat.getCurrencyInstance();
297             amount=Double.parseDouble(b4.getText());
298             principal=Double.parseDouble(b1.getText());
299            
300             if(b3.getText().equals("")){
301                 rate=Double.parseDouble(b2.getText());
302                 double year=(int)((Math.log(amount)/Math.log(1+rate))-(Math.log(principal)/Math.log(1+rate)));;
303                 output="年份"+currencyformatter.format(year) + "\n";
304                 text.setText(output);
305             }
306             else{
307                 if(b2.getText().equals("")){
308                     int year=Integer.parseInt(b3.getText());
309                     rate=((Math.pow(amount/principal, 1.0/year))-1);
310                     output="利率"+currencyformatter.format(rate) + "\n";
311                     text.setText(output);
312                 }
313                 else{
314                     JOptionPane.showMessageDialog(null, "利率和存期输入一个即可");
315                 }
316             }
317             
318         }
319     }
320     private class c6ActionEventHander implements ActionListener
321     {
322         public void actionPerformed(ActionEvent e)
323         {
324             double principal;
325             double amount;
326             double rate;
327             double trate;
328            
329             NumberFormat currencyformatter=NumberFormat.getCurrencyInstance();
330             String output="月"+"/t"+"等额还款"+"/n";
331             
332            //  principal=Double.parseDouble(b1.getText());
333              rate=Double.parseDouble(b5.getText()); 
334              double year=Integer.parseInt(b3.getText());
335              principal = Double.parseDouble(b1.getText()); // 字符串转化为数字
336                  if (b4.getText().equals("")) {
337                     
338                          rate=rate/12;
339                          trate=rate+(double)1;
340                          for(int i=1;i<year*12;i++){
341                              trate*=(rate+(double)1);
342                              
343                      }
344                      amount=(principal*trate*rate)/(trate-(double)1);
345                             output +="每月"+ currencyformatter.format(amount) + "\n";
346                             text.setText(output);
347                  }
348                  else{
349                      JOptionPane.showMessageDialog(null, "请输入贷款金额(本金)");
350                  }
351         }
352     }
353     public static void main(String[] args)
354     {
355          Fuli2 frame=new Fuli2();
356         frame.setVisible(true);
357         frame.setSize(600,450); 
358       frame.setResizable(false);
359     }
360 }

 

转载于:https://www.cnblogs.com/xiaochenxi/p/5301691.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/dengyajiu8101/article/details/101456014

智能推荐

mysql进阶:optimize table 优化表命令 Table does not support optimize, doing recreate + analyze instead-程序员宅基地

文章浏览阅读1.1w次,点赞3次,收藏13次。optimize table table_name1. 问题描述在使用mysql的时候有时候,可能会发现尽管一张表删除了许多数据,但是这张表表的数据文件和索引文件却奇怪的没有变小。这是因为mysql在删除数据(特别是有Text和BLOB)的时候,会留下许多的数据空洞/碎片,这些空洞会占据原来数据的空间,所以文件的大小没有改变。这些空洞在以后插入数据的时候可能会被再度利用起来,当然也有可能一直存在。这种空洞不仅额外增加了存储代价,同时也因为数据碎片化降低了表的扫描效率。2. 使用场景如果您已经删除._table does not support optimize, doing recreate + analyze instead

[完全背包] 货币系统(完全背包+求方案数)_完全背包求具体方案-程序员宅基地

文章浏览阅读293次。文章目录0. 前言1. 完全背包+求方案数0. 前言相关:[背包] 背包问题算法模板(模板)强相关:[完全背包] 买书(完全背包+裸题)1. 完全背包+求方案数1021. 货币系统重点: 完全背包、求方案数和 [完全背包] 买书(完全背包+裸题) 一模一样。就注意下初始化 f[0]=1,优化到一维时,完全背包问题体积从小到大进行枚举即可。代码:#include <iostream>using namespace std;typedef long long _完全背包求具体方案

web_Tomcat服务部署._tomcat部署web项目-程序员宅基地

文章浏览阅读228次。一.Tomcat概述Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP程序的首选。一般来说,Tomcat虽然和Apache或者Nginx这些Web服务器一样,具有处理HTML页面的功能,然而由于其处理静态HTML的能力远不及Apache或者Nginx,所以Tomcat通常是作为一个Servlet和JSP容器,单独运行在后端。二.Tomcat核心组件1.核心组件Web 容器:完成 W_tomcat部署web项目

Winner Winner——状压dp(待定)_if(winner(close),winner(close)*100,20),volstick;-程序员宅基地

文章浏览阅读152次。题目描述The FZU Code Carnival is a programming competetion hosted by the ACM-ICPC Training Center of Fuzhou University. The activity mainly includes the programming contest like ACM-ICPC and strive to p..._if(winner(close),winner(close)*100,20),volstick;

cocos2d-x动作系统浅析-程序员宅基地

文章浏览阅读129次。尊重作者劳动,转载时请标明文章出处。作者:Bugs Bunny地址:http://www.cnblogs.com/cocos2d-x/archive/2012/03/13/2393898.html在上一篇博文中我们对cocos2d-x的动作使用有了初步了解。今天,我们将通过阅读部分cocos2d-x源码来了解这个动作系统是如何运作的,以及在使用时还有什么细节需要特别注意。小弟初学cocos..._cocos2d-x 运动系统

Pytorch Random Erasing-程序员宅基地

文章浏览阅读3k次。RandomErasing 随机擦除训练模型时,随机选取一个图片的矩形区域,将这个矩形区域的像素值用随机值或者平均像素值代替,产生局部遮挡的效果。该数据增强可以与随机切除、随机翻转等数据增强结合起来使用。在ReID、图像分类领域可以作为升点trick。codeimport cv2import mathimport randomimport torchvision.transforms as transformsfrom torch.utils.tensorboard import .._pytorch random erasing

随便推点

jQuery.validator验证无效的可能原因_jquery.validator 有时undefined有时没问题-程序员宅基地

文章浏览阅读3.9k次。最近用jQuery.validator做表单的前端验证,_jquery.validator 有时undefined有时没问题

Unity坐标系大全(屏幕转3d坐标)_unity 屏幕坐标转换成三维坐标-程序员宅基地

文章浏览阅读531次。坐标系1.世界坐标系:以世界原点为坐标原点建立的三维坐标系.2.本地坐标系:以自身父物体为原点建立的三维坐标系.3.屏幕坐标系:以屏幕左下角为原点建立的二维坐标系,输出设备的坐标一般为屏幕坐标.4.视口坐标系:以相机屏幕左下角为原点建立的一个二维坐标系,屏幕坐标和视口坐标一样,只不过视口坐标的Z轴是摄像机的Z轴,屏幕坐标没有Z轴...._unity 屏幕坐标转换成三维坐标

ThreadPoolTaskExecutor使用实践_threadpooltaskexecutor结合disposablebean-程序员宅基地

文章浏览阅读1.7k次,点赞2次,收藏5次。后台开发中,经常有一些非主流程业务要处理,为了提升主业务处理速度,可使用ThreadPoolTaskExecutor线程池来异步处理配置 java config @Bean public ThreadPoolTaskExecutor taskExecutor() { ThreadPoolTaskExecutor poolExecutor = new Thread..._threadpooltaskexecutor结合disposablebean

在瑞萨CS+(Cube Suite+)使用中文注释及中文字符串的方法_瑞萨 cs+中文注释-程序员宅基地

文章浏览阅读1.8k次。一、测试环境瑞萨Cube Suite+ for CA,CX V4.00.00,其他请自行测试。二、设置1.在菜单Tool中,选中Options,在弹出的窗口中,进行如下图的设置:2.按下图步骤,在工程的Build Tool处右键,在“Kanji character code of source”处选择“ECU_JP(-ze)”..._瑞萨 cs+中文注释

Python dir、__builtin__内置函数_dir(__builtin__)-程序员宅基地

文章浏览阅读1.1k次。科学计数法:&gt;&gt; format(2**20, '.2e')'1.05e+06'小数 ⇒ 百分数&gt;&gt; format(.1234, '.1%')12.3%_dir(__builtin__)

AI中台架构模型解析-程序员宅基地

文章浏览阅读1.8k次。传统上,企业部署AI应用,一般通过单点开发的方式,即“烟囱式”架构部署AI应用。海量AI应用场景爆发使得原来传统的“烟囱式“AI开发流程无法跟上业务的快速变化,开发速度慢、周期长。越来越多..._ai中台模型