复利计划1.0

package fuli;

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.NumberFormat;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;

import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;

//VS4E -- DO NOT REMOVE THIS LINE!
public class fuli extends JFrame {

    private static final long serialVersionUID = 1L;
    private JLabel jLabel0;
    private JLabel jLabel1;
    private JPanel jPanel1;
    private JPanel jPanel0;
    private JLabel jLabel2;
    private JButton jButton4;
    private JLabel jLabel3;
    private JTextField jTextField0;
    private JTextField jTextField1;
    private JTextField jTextField2;
    private JTextField jTextField3;
    private static final MouseEvent event2 = null;
    private JComboBox jComboBox0;
    private JComboBox jComboBox1;
    private JButton jButton1;
    private JLabel jLabel4;
    private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
    public fuli() {
        initComponents();
    }

    private void initComponents() {
        setLayout(new GroupLayout());
        add(getJPanel0(), new Constraints(new Leading(9, 304, 10, 10), new Leading(80, 361, 10, 10)));
        add(getJComboBox1(), new Constraints(new Leading(23, 10, 10), new Leading(19, 10, 10)));
        setSize(320, 449);
    }

    private JLabel getJLabel4() {
        if (jLabel4 == null) {
            jLabel4 = new JLabel();
            jLabel4.setText("%");
        }
        return jLabel4;
    }

    private JButton getJButton1() {
        if (jButton1 == null) {
            jButton1 = new JButton();
            jButton1.setText("确定");
            jButton1.addMouseListener(new MouseAdapter() {

                public void mouseClicked(MouseEvent event) {
                    jButton1MouseMouseClicked(event);
                }
            });
        }
        return jButton1;
    }

    private JComboBox getJComboBox1() {
        if (jComboBox1 == null) {
            jComboBox1 = new JComboBox();
            jComboBox1.setModel(new DefaultComboBoxModel(new Object[] { "复利计算", "单利计算" }));
            jComboBox1.setDoubleBuffered(false);
            jComboBox1.setBorder(null);
            jComboBox1.addMouseListener(new MouseAdapter() {
            });
        }
        return jComboBox1;
    }

    private JComboBox getJComboBox0() {
        if (jComboBox0 == null) {
            jComboBox0 = new JComboBox();
            jComboBox0.setModel(new DefaultComboBoxModel(new Object[] { "终值计算", "本金计算" ,"年限计算","利息计算"}));
            jComboBox0.setDoubleBuffered(false);
            jComboBox0.setBorder(null);
            jComboBox0.addMouseListener(new MouseAdapter() {
        });
        }
        return jComboBox0;
    }

    private JTextField getJTextField3() {
        if (jTextField3 == null) {
            jTextField3 = new JTextField(10);
        }
        return jTextField3;
    }

    private JTextField getJTextField2() {
        if (jTextField2 == null) {
            jTextField2 = new JTextField();
        }
        return jTextField2;
    }

    private JTextField getJTextField1() {
        if (jTextField1 == null) {
            jTextField1 = new JTextField(10);
        }
        return jTextField1;
    }

    private JTextField getJTextField0() {
        if (jTextField0 == null) {
            jTextField0 = new JTextField(10);
        }
        return jTextField0;
    }

    private JLabel getJLabel3() {
        if (jLabel3 == null) {
            jLabel3 = new JLabel();
            jLabel3.setText("终值");
        }
        return jLabel3;
    }

    private JButton getJButton4() {
        if (jButton4 == null) {
            jButton4 = new JButton();
            jButton4.setText("确定");
            jButton4.addMouseListener(new MouseAdapter() {

                public void mouseClicked(MouseEvent event) {
                    jButton4MouseMouseClicked(event);
                }
            });
        }
        return jButton4;
    }

    private JLabel getJLabel2() {
        if (jLabel2 == null) {
            jLabel2 = new JLabel();
            jLabel2.setText("利率");
        }
        return jLabel2;
    }

    private JPanel getJPanel0() {
        if (jPanel0 == null) {
            jPanel0 = new JPanel();
            jPanel0.setBorder(new LineBorder(Color.red, 1, false));
            jPanel0.setLayout(new GroupLayout());
            jPanel0.add(getJPanel1(), new Constraints(new Leading(17, 261, 10, 10), new Leading(74, 264, 10, 10)));
            jPanel0.add(getJComboBox0(), new Constraints(new Leading(14, 10, 10), new Leading(20, 10, 10)));
            jPanel0.add(getJButton1(), new Constraints(new Leading(119, 10, 10), new Leading(19, 12, 12)));
        }
        return jPanel0;
    }

    private JPanel getJPanel1() {
        if (jPanel1 == null) {
            jPanel1 = new JPanel();
            jPanel1.setBorder(new LineBorder(Color.black, 1, false));
            jPanel1.setLayout(new GroupLayout());
            jPanel1.add(getJLabel0(), new Constraints(new Leading(14, 10, 10), new Leading(26, 10, 10)));
            jPanel1.add(getJLabel1(), new Constraints(new Leading(14, 12, 12), new Leading(113, 10, 10)));
            jPanel1.add(getJLabel2(), new Constraints(new Leading(12, 12, 12), new Leading(70, 10, 10)));
            jPanel1.add(getJButton4(), new Constraints(new Leading(74, 10, 10), new Leading(161, 10, 10)));
            jPanel1.add(getJLabel3(), new Constraints(new Leading(14, 12, 12), new Leading(215, 10, 10)));
            jPanel1.add(getJTextField0(), new Constraints(new Leading(60, 182, 10, 10), new Leading(26, 12, 12)));
            jPanel1.add(getJTextField3(), new Constraints(new Leading(60, 178, 12, 12), new Leading(213, 12, 12)));
            jPanel1.add(getJTextField1(), new Constraints(new Leading(60, 182, 12, 12), new Leading(113, 12, 12)));
            jPanel1.add(getJLabel4(), new Constraints(new Leading(56, 26, 12, 12), new Leading(72, 12, 12)));
            jPanel1.add(getJTextField2(), new Constraints(new Leading(74, 158, 12, 12), new Leading(70, 12, 12)));
        }
        return jPanel1;
    }

    private JLabel getJLabel1() {
        if (jLabel1 == null) {
            jLabel1 = new JLabel();
            jLabel1.setText("年限");
        }
        return jLabel1;
    }

    private JLabel getJLabel0() {
        if (jLabel0 == null) {
            jLabel0 = new JLabel();
            jLabel0.setText("本金");
        }
        return jLabel0;
    }

    private static void installLnF() {
        try {
            String lnfClassname = PREFERRED_LOOK_AND_FEEL;
            if (lnfClassname == null)
                lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
            UIManager.setLookAndFeel(lnfClassname);
        } catch (Exception e) {
            System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL + " on this platform:" + e.getMessage());
        }
    }

    /**
    * Main entry of the class.
    * Note: This class is only created so that you can easily preview the result at runtime.
    * It is not expected to be managed by the designer.
    * You can modify it as you like.
    */
    public static void main(String[] args) {
        installLnF();
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                fuli frame = new fuli();
                frame.setDefaultCloseOperation(fuli.EXIT_ON_CLOSE);
                frame.setTitle("复利、单利计算 ");
                frame.getContentPane().setPreferredSize(frame.getSize());
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }

    //终值,本金
    private void jButton1MouseMouseClicked(MouseEvent event) {

        if (jComboBox0.getSelectedItem() == "终值计算") {
            jPanel1 = new JPanel();
            jTextField0 = new JTextField();
            jTextField1 = new JTextField();
            jTextField2 = new JTextField();
            jTextField3 = new JTextField();

        }
        else if (jComboBox0.getSelectedItem() == "本金计算") {
            jPanel1 = new JPanel();
            this.jLabel0.setText("终值");
            this.jLabel3.setText("本金");
        }
        else if (jComboBox0.getSelectedItem() == "年限计算") {
            jPanel1 = new JPanel();
            this.jLabel0.setText("本金");
            this.jLabel1.setText("终值");
            this.jLabel3.setText("年限");
        }
        else if (jComboBox0.getSelectedItem() == "利息计算") {
            jPanel1 = new JPanel();
            this.jLabel0.setText("本金");
            this.jLabel3.setText("利息");
            this.jLabel1.setText("年限");
        }
    }

    private void jButton4MouseMouseClicked(MouseEvent event) {
        NumberFormat currencyformatter = NumberFormat.getCurrencyInstance();
        double p = Double.parseDouble(jTextField0.getText());
        double r = Double.parseDouble(jTextField1.getText());
        double n = Double.parseDouble(jTextField2.getText());
        double f=0;
        if (jComboBox1.getSelectedItem() == "复利计算") {

            if (jComboBox0.getSelectedItem() == "终值计算") {
                f = p * Math.pow((1 + 0.01*r),n);
            }
            else if (jComboBox0.getSelectedItem() == "本金计算") {
                f = p/Math.pow((1+0.01*r), n);
            }
            else if (jComboBox0.getSelectedItem() == "年限计算") {
                f=0;
            }
            else if (jComboBox0.getSelectedItem() == "利息计算") {
                f=p * Math.pow((1 + 0.01*r),n)-1;
            }
        }
        else {
            if (jComboBox0.getSelectedItem() == "终值计算") {
                f = p*(1+0.01*r*n);
            }
            else if (jComboBox0.getSelectedItem() == "本金计算") {
                f = p/(1+0.01*r*n);
            }
            else if (jComboBox0.getSelectedItem() == "年限计算") {
                f=0;
            }
            else if (jComboBox0.getSelectedItem() == "利息计算") {
                f=p*(1+0.01*r*n)-p;
            }
        }
        jTextField3.setText(String.valueOf(f));
    }
}


时间: 2024-11-04 19:27:05

复利计划1.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之再遇JUnit

复利计算器4.0之再遇JUnit 前言    虽然之前的复利计算器版本已经尝试过使用JUnit单元测试,但由于没有系统性地学习过JUnit的使用,用得并不好,主要问题表现在测试的场景太少,并没有达到测试所需的全面性,没能体现JUnit这一神器的精髓所在,为此本版本的复利计算器在JUnit单元测试方面做了一些完善. 源代码包结构 如上图所示,我把测试类统一放在新建的test源码文件下(test打错了,已改),以便和程序代码分离,方便操作. 细心看你就能发现,test目录下的包和程序SRC目录下相应

0319 复利计算器4.0

  /** 程序完成时间: 3月19日 9:50pm 发表时间: 3月20日 0:18am 此版本是在前三个版本的基础上添加了 等额本息还贷计算 的新功能 并且按照实验要求增强了系统的健壮性,保证在输入一部分的错误的 数据,后程序不会崩溃.例如是在输入int或者是输入double类型的 地方,输入了字符,是会提示并且允许重新输入. 并且通过宏定义使得代码变得简洁,还有简化了修改的操作,还认识 到宏定义的妙用是可以使得编程变得简单,还可以增大代码的复用性. **/ 1 #include<stdio

复利计算3.0 心得

这个星期老师在原来复利计算上布置了新的任务,让我慢慢的进入状态来一步一步的完善我的代码,虽然运行的代码不够“豪华”,但是自己有在感觉到在一点点的进步和总结,会慢慢发现每次写总结会对以后的编程之路有益,因为是在记录自己一点点的进步和解决疑惑之处,因为基础问题,在刚开始的编程之路会有很多缺陷,但是会一步步成长起来的,因为最近有学网页制作界面,发现jsp的界面编写会比java简单一些,所以这次总结后,有时间会去尝试用jsp来总结编写,因为感觉用eclipse来创建窗口太复杂. 回顾布置的问题,并附上操

0316复利计算器3.0

#include<stdio.h> #include<math.h> double benjin=0,W=0; double year=0; int N=1; double lilv; void danli(){ printf("请输入要存入的本金:"); scanf("%lf",&benjin); printf("请输入年利率:"); scanf("%lf",&lilv); print

复利计算4.0单元测试

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

0406复利计算5.0

1 package kxj; 2 import java.util.Scanner; 3 4 public class Fulijisuan { 5 public static double p,i,f ; 6 public static double n; 7 public static int a=0; 8 9 static double A[] = new double[10]; 10 static double B[] = new double[10]; 11 static double

复利计算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万

复利计算4.0

测试模块(场景) 测试输入 预期结果 运行结果 bug跟踪 计算复利 (本金,利率,期限) 1 (10000, 0.05, 5) 12762.82 12762.82 2 (-100, 0.05,  5) 本金输入错误请重新输入 本金输入错误请重新输入 3 (10000,  -0.05, 5) 利率输入错误请重新输入 利率输入错误请重新输入 4 (10000,0.05,-20) 期限输入错误请重新输入 期限输入错误请重新输入     计算本金 (本利和,利率,期限) 1 (10000,0.05,5