复利计算2.0

  1 package fulijisuan;
  2
  3 import java.awt.event.MouseAdapter;
  4 import java.awt.event.MouseEvent;
  5
  6 import javax.swing.JButton;
  7 import javax.swing.JFrame;
  8 import javax.swing.JLabel;
  9 import javax.swing.JRadioButton;
 10 import javax.swing.JTextField;
 11 import javax.swing.SwingUtilities;
 12 import javax.swing.UIManager;
 13
 14 import org.dyno.visual.swing.layouts.Constraints;
 15 import org.dyno.visual.swing.layouts.GroupLayout;
 16 import org.dyno.visual.swing.layouts.Leading;
 17 import org.dyno.visual.swing.layouts.Trailing;
 18
 19 //VS4E -- DO NOT REMOVE THIS LINE!
 20 public class text1 extends JFrame {
 21
 22     private static final long serialVersionUID = 1L;
 23     private JButton jButton1;
 24     private JButton jButton0;
 25     private JLabel jLabel0;
 26     private JLabel jLabel1;
 27     private JLabel jLabel2;
 28     private JTextField jTextField0;
 29     private JTextField jTextField1;
 30     private JTextField jTextField2;
 31     private JLabel jLabel3;
 32     private JLabel jLabel4;
 33     private JButton jButton2;
 34     private JTextField jTextField3;
 35     private JTextField jTextField4;
 36     private JRadioButton jRadioButton0;
 37     public text1() {
 38         initComponents();
 39     }
 40
 41     private void initComponents() {
 42         setLayout(new GroupLayout());
 43         add(getJLabel0(), new Constraints(new Leading(34, 12, 12), new Leading(18, 10, 10)));
 44         add(getJLabel1(), new Constraints(new Leading(33, 12, 12), new Leading(64, 12, 12)));
 45         add(getJLabel2(), new Constraints(new Leading(32, 12, 12), new Leading(113, 10, 10)));
 46         add(getJButton0(), new Constraints(new Leading(9, 12, 12), new Leading(259, 29, 10, 10)));
 47         add(getJButton2(), new Constraints(new Leading(126, 10, 10), new Leading(259, 12, 12)));
 48         add(getJButton1(), new Constraints(new Leading(239, 10, 10), new Leading(259, 12, 12)));
 49         add(getJLabel4(), new Constraints(new Leading(30, 12, 12), new Leading(200, 10, 10)));
 50         add(getJLabel3(), new Constraints(new Leading(30, 12, 12), new Leading(158, 10, 10)));
 51         add(getJRadioButton0(), new Constraints(new Trailing(12, 109, 171), new Leading(62, 12, 12)));
 52         add(getJRadioButton1(), new Constraints(new Leading(246, 10, 10), new Leading(131, 10, 10)));
 53         add(getJTextField0(), new Constraints(new Leading(91, 95, 10, 10), new Leading(18, 10, 10)));
 54         add(getJTextField2(), new Constraints(new Leading(91, 94, 12, 12), new Leading(109, 12, 12)));
 55         add(getJTextField3(), new Constraints(new Leading(91, 94, 12, 12), new Leading(154, 12, 12)));
 56         add(getJTextField4(), new Constraints(new Leading(90, 96, 12, 12), new Leading(198, 12, 12)));
 57         add(getJTextField1(), new Constraints(new Leading(92, 93, 88, 88), new Leading(64, 24, 12, 12)));
 58         setSize(320, 388);
 59     }
 60
 61     private JRadioButton getJRadioButton1() {
 62         if (jRadioButton1 == null) {
 63             jRadioButton1 = new JRadioButton();
 64             jRadioButton1.setSelected(false);
 65             jRadioButton1.setText("算本金");
 66             jRadioButton1.addMouseListener(new MouseAdapter() {
 67
 68                 public void mouseClicked(MouseEvent event) {
 69                     jRadioButton1MouseMouseClicked(event);
 70                 }
 71             });
 72         }
 73         return jRadioButton1;
 74     }
 75
 76     private JRadioButton getJRadioButton0() {
 77         if (jRadioButton0 == null) {
 78             jRadioButton0 = new JRadioButton();
 79             jRadioButton0.setSelected(false);
 80             jRadioButton0.setText("算存款");
 81             jRadioButton0.addMouseListener(new MouseAdapter() {
 82
 83                 public void mouseClicked(MouseEvent event) {
 84                     jRadioButton0MouseMouseClicked(event);
 85                 }
 86             });
 87         }
 88         return jRadioButton0;
 89     }
 90
 91     private JTextField getJTextField4() {
 92         if (jTextField4 == null) {
 93             jTextField4 = new JTextField();
 94         }
 95         return jTextField4;
 96     }
 97
 98     private JTextField getJTextField3() {
 99         if (jTextField3 == null) {
100             jTextField3 = new JTextField();
101         }
102         return jTextField3;
103     }
104
105     private JButton getJButton2() {
106         if (jButton2 == null) {
107             jButton2 = new JButton();
108             jButton2.setText("单利计算");
109             jButton2.addMouseListener(new MouseAdapter() {
110
111                 public void mouseClicked(MouseEvent event) {
112                     jButton2MouseMouseClicked(event);
113                 }
114             });
115         }
116         return jButton2;
117     }
118
119     private JLabel getJLabel4() {
120         if (jLabel4 == null) {
121             jLabel4 = new JLabel();
122             jLabel4.setText("利息:");
123         }
124         return jLabel4;
125     }
126
127     private JLabel getJLabel3() {
128         if (jLabel3 == null) {
129             jLabel3 = new JLabel();
130             jLabel3.setText("存款:");
131         }
132         return jLabel3;
133     }
134
135     private JTextField getJTextField2() {
136         if (jTextField2 == null) {
137             jTextField2 = new JTextField();
138         }
139         return jTextField2;
140     }
141
142     private JTextField getJTextField1() {
143         if (jTextField1 == null) {
144             jTextField1 = new JTextField();
145         }
146         return jTextField1;
147     }
148
149     private JTextField getJTextField0() {
150         if (jTextField0 == null) {
151             jTextField0 = new JTextField();
152         }
153         return jTextField0;
154     }
155
156     private JLabel getJLabel2() {
157         if (jLabel2 == null) {
158             jLabel2 = new JLabel();
159             jLabel2.setText("年限:");
160         }
161         return jLabel2;
162     }
163
164     private JLabel getJLabel1() {
165         if (jLabel1 == null) {
166             jLabel1 = new JLabel();
167             jLabel1.setText("利率:");
168         }
169         return jLabel1;
170     }
171
172     private JLabel getJLabel0() {
173         if (jLabel0 == null) {
174             jLabel0 = new JLabel();
175             jLabel0.setText("本金:");
176         }
177         return jLabel0;
178     }
179
180     private JButton getJButton0() {
181         if (jButton0 == null) {
182             jButton0 = new JButton();
183             jButton0.setText("复利计算");
184             jButton0.addMouseListener(new MouseAdapter() {
185
186                 public void mouseClicked(MouseEvent event) {
187                     jButton0MouseMouseClicked(event);
188                 }
189             });
190         }
191         return jButton0;
192     }
193
194     private JButton getJButton1() {
195         if (jButton1 == null) {
196             jButton1 = new JButton();
197             jButton1.setText("清除");
198             jButton1.addMouseListener(new MouseAdapter() {
199
200                 public void mouseClicked(MouseEvent event) {
201                     jButton1MouseMouseClicked(event);
202                 }
203             });
204         }
205         return jButton1;
206     }
207
208     private static void installLnF() {
209         try {
210             String lnfClassname = PREFERRED_LOOK_AND_FEEL;
211             if (lnfClassname == null)
212                 lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
213             UIManager.setLookAndFeel(lnfClassname);
214         } catch (Exception e) {
215             System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL + " on this platform:" + e.getMessage());
216         }
217     }
218
219     /**
220     * Main entry of the class.
221     * Note: This class is only created so that you can easily preview the result at runtime.
222     * It is not expected to be managed by the designer.
223     * You can modify it as you like.
224     */
225     boolean suanfa = true ;
226     private JRadioButton jRadioButton1;
227     private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
228     public static void main(String[] args) {
229         installLnF();
230         SwingUtilities.invokeLater(new Runnable() {
231             public void run() {
232                 text1 frame = new text1();
233                 frame.setDefaultCloseOperation(text1.EXIT_ON_CLOSE);
234                 frame.setTitle("text1");
235                 frame.getContentPane().setPreferredSize(frame.getSize());
236                 frame.pack();
237                 frame.setLocationRelativeTo(null);
238                 frame.setVisible(true);
239             }
240         });
241     }
242
243     private void jButton0MouseMouseClicked(MouseEvent event) {
244         double p=0,i=0,f=0,j=0;
245         double s=1;
246          int n=0;
247          i = Double.parseDouble(jTextField1.getText());
248          n = Integer.parseInt(jTextField2.getText());
249          if(suanfa == false)
250          {
251              p = Double.parseDouble(jTextField0.getText());
252
253          for(int a = 0;a < n;a++){
254          s = s * (1 + i);
255          }
256          f =  p * s;
257          j = f - p;
258          this.jTextField3.setText(String.format("%.2f", f));
259          this.jTextField4.setText(String.format("%.2f", j));
260          }
261          else{
262              f = Double.parseDouble(jTextField3.getText());
263              for(int a = 0;a<n;a++){
264                  s= (i+1)*s;
265              }
266              p=f*(1/s);
267              j=f-p;
268
269             this.jTextField0.setText(String.format("%.2f", p));
270          this.jTextField4.setText(String.format("%.2f", j));
271          }
272     }
273
274     private void jButton1MouseMouseClicked(MouseEvent event) {
275         this.jTextField0.setText(null);
276          this.jTextField1.setText(null);
277          this.jTextField2.setText(null);
278          this.jTextField3.setText(null);
279          this.jTextField4.setText(null);
280     }
281
282     private void jButton2MouseMouseClicked(MouseEvent event) {
283         double p=0,i=0,j=0,f=0;;
284          int n=0;
285
286          i = Double.parseDouble(jTextField1.getText());
287          n = Integer.parseInt(jTextField2.getText());
288          if(suanfa == false){
289          p = Double.parseDouble(jTextField0.getText());
290          j=p*i*n;
291          f=j+p;
292          this.jTextField3.setText(String.format("%.2f", f));
293          this.jTextField4.setText(String.format("%.2f", j));
294          }
295          else{
296              f = Double.parseDouble(jTextField3.getText());
297              p = f *(1/(1+i*n));
298              j=f-p;
299
300             this.jTextField0.setText(String.format("%.2f", p));
301          this.jTextField4.setText(String.format("%.2f", j));
302          }
303     }
304
305     private void jRadioButton0MouseMouseClicked(MouseEvent event) {
306         suanfa = false;
307         jRadioButton1.setSelected(false);
308     }
309
310     private void jRadioButton1MouseMouseClicked(MouseEvent event) {
311         jRadioButton0.setSelected(false);
312         suanfa = true;
313     }
314
315 }

实现功能点:

1.输入本金、利率、年限复利、单利计算存款;

2.输入利率、年限、存款复利、单利计算本金;

3.一键清除输入框内数据。

运行结果:

时间: 2024-10-29 19:08:35

复利计算2.0的相关文章

0330复利计算4.0单元测试

测试模块 输入测试 预期结果 运行结果 复/单利计算本息  (本金,年利率,年限)      1000,0.03,10 复利:1343.92 单利:1300.0 √  0,0.03,10 复利:0.0 单利:0.0   √  1000,0,10 复利:1000.0 单利:1000.0  √  1000,0.03,10 复利:1000.0 单利:1000.0  √ 复/单利计算本金   (本息,年利率,年限)      1000,0.03,10 复利:744.09 单利:769.23  √  0,

复利计算4.0单元测试

——————————复利计算程序单元测试报告—————————— ————————————4.0 单元测试—————————————— ————————————————要求—————————————— 根据复利计算程序,进行Junit单元测试. 在测试会出现什么场面,有哪些情况的结果? 所要期待的返回值是多少? 写测试程序. 运行测试. 完成结果: 测试一:复利计算本息 1.期待的返回值是13439,实际值是13439.16,允许有1.0以内的误差. 2.测试程序: 此为复利计算: 在允许误差为

复利计算6.0

一.主要功能与需求分析 1.本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按复利计算公式来计算就是:1,000,000×(1+3%)^30 2.如果按照单利计算,本息的最终收益 3.假如30年之后要筹措到300万元的养老金,平均的年回报率是3%,那么,现在必须投入的本金是多少呢? 4.利率这么低,复利计算收益都这么厉害了,如果拿100万元去买年报酬率10%的股票,若一切顺利,过多长时间,100万元就变成200万元呢? 5.如果我希望在十年内将100万

复利计算3.0代码

#include<stdio.h> #include<math.h> void List(); void A(); void B(); void C(); void D(); void E(); void F(); main() { int sel; List(); printf("\t请选择:"); while(scanf("%d",&sel)!=1||sel<0||sel>6)//防止输入的是字符以及输入的数字不是整数

0317复利计算3.0

1 import java.util.Scanner; 2 3 public class text { 4 public static void main(String[] args) { 5 6 7 do { 8 Scanner scanner = new Scanner(System.in); 9 System.out.println(" "); 10 System.out.print("请选择(0为退出,1为算本息,2为算本金,3为算投资,4为算n年后资产总值):&qu

复利计算3.0

import java.util.Scanner; public class Money { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入计算方式:1.单利计算 2.复利计算 3.本金计算 4.股票期限计算 5.利率计算 6.资产总值计算"); // 选择计算方式 int choose = scanner.nextInt

0330复利计算4.0(改)

1 import java.util.Scanner; 2 3 public class text { 4 5 public static void main(String[] args) { 6 while (true) { 7 Scanner scanner = new Scanner(System.in); 8 System.out.println("----------------------------"); 9 System.out.println(" 1.复利计

复利计算1.0,2.0

1.客户说:帮我开发一个复利计算软件. 完成复利公式计算程序,并成功PUSH到github上. 截止时间:3.10晚12点之前. 按照这个要求完成了. 演示. 计算:本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按复利计算公式来计算就是:1,000,000×(1+3%)^30 #include<stdio.h> #include<math.h> void view() { printf(" | 单/复利计算 |\n"

软件工程---复利计算6.0

代码如下: import java.awt.Container; import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener; import javax.swing.JButton;import javax.swing.JComboB