结队2.0(复利计算)

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

posted @ 2016-04-14 17:47  39谭宇森  阅读(218)  评论(1编辑  收藏  举报