0311 the simple interest and expectation of software engineering compound interest

Source: Internet
Author: User

Package Ch1;import Java.awt.borderlayout;import Java.awt.component;import java.awt.dimension;import Java.awt.flowlayout;import Java.awt.graphics;import Java.awt.gridlayout;import Java.awt.Toolkit;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.awt.image.bufferedimage;import Java.io.file;import Java.io.ioexception;import Java.text.numberformat;import Javax.imageio.imageio;import Javax.swing.imageicon;import Javax.swing.jbutton;import Javax.swing.jframe;import Javax.swing.JLabel;import Javax.swing.joptionpane;import Javax.swing.jpanel;import Javax.swing.jscrollpane;import Javax.swing.JTextArea; Import Javax.swing.jtextfield;import Org.omg.cosnaming.namingcontextextpackage.addresshelper;public class Fuli Extends JFrame {private static final long Serialversionuid = 3347254632537686808l;private JLabel A1;//Tag Private JLabel a 2;private JLabel a3;private JLabel a4;private JTextField B1; Principal private JTextField B2; Interest rate private JTextField B3; Year Private JteXtfield b4; Expected private JButton c1;private JButton c2;private JButton c3;private jtextarea text; Displays a multiline area of plain text private JPanel toolbar = new JPanel ();p ublic Fuli () {settitle ("Compound deposit Application"); Creatcomponents ();// Create part layoutcomponents (); Design part registerhandlers (); Mouse Monitor setdefaultcloseoperation (jframe.exit_on_close);p ack ();} private void Creatcomponents () {a1 = new JLabel ("Principal"), a2 = new JLabel ("annual interest rate"), a3 = new JLabel ("Number of Years"), A4 = new JLabel ("period B1 = new JTextField (ten), b2 = new JTextField, B3 = new JTextField (ten), B4 = new JTextField, C1 = new JButton ("compounding" C2 = new JButton ("clear"), C3 = New JButton ("simple Interest"); text = new JTextArea ();} private void Layoutcomponents () {setlayout (New FlowLayout ()); JPanel Panel1 = new JPanel ();p anel1.add (A1);p Anel1.add (B1); JPanel Panel2 = new JPanel ();p anel2.add (A2);p anel2.add (B2); JPanel panel3 = new JPanel ();p anel3.add (A3);p Anel3.add (B3); JPanel panel6 = new JPanel ();p anel6.add (A4);p anel6.add (B4); JPanel Leftpanel = new JPanel (New GridLayout (3, 1)); Leftpanel.add (PANEL1); Leftpanel.add (Panel2); Leftpanel.add (PANEL3); Leftpanel.add (PANEL6); JScrollPane Panel5 = new JScrollPane (text);p anel5.setpreferredsize (new Dimension (+)); Toolbar.add (C1); Toolbar.add (C2); Toolbar.add (C3); add (Leftpanel); add (Panel5); Add (toolbar, borderlayout.east);} private void Registerhandlers () {C1actioneventhander hander1 = new C1actioneventhander (); C1.addactionlistener (hander1 ); C2actioneventhander hander2 = new C2actioneventhander (); C2.addactionlistener (hander2); C3actioneventhander Hander3 = new C3actioneventhander (); C3.addactionlistener (Hander3);} Private class C1actioneventhander implements ActionListener {public void actionperformed (ActionEvent e) {double Principal;double amount;double rate;int N; NumberFormat currencyformatter = Numberformat.getcurrencyinstance (); The string is converted to a numeric string output = "Year" + "/" + "compound deposit"; int year =1;rate = double.parsedouble (B2.gettext ()); n = Integer.parseint (b3. GetText ()), if (B1.gettext (). Equals ("")) {if (B4.gettext (). Equals ("")) {Joptionpane.showmessaGedialog (NULL, "Please enter the principal or expected value");} Else{amount = Double.parsedouble (B4.gettext ());p rincipal=0;while (year <= N) {principal=amount/(Math.pow (1 + rate, Year): Year = year + 1;} output= "Principal" +currencyformatter.format (Principal) + "\ n"; text.settext (output);}}  else {principal = Double.parsedouble (B1.gettext ());//String converted to numeric if (B4.gettext (). Equals ("")) {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{joptionpane.showmessagedialog (NULL, "the principal and expected value are entered in one can");}}} Private class C2actioneventhander implements ActionListener {public void actionperformed (ActionEvent e) {b1.settext ("") ; B2.settext (""); B3.settext (""); B4.settext (""); Text.settext ("");}} Private class C3actioneventhander implements ActionListener {public void actionperformed (ActionEvent e) {double Principal;double amount;double rate;int N; NumberFormat currencyformatter = Numberformat.getcurrencyinstance ();String output = "Year" + "/" + "simple interest deposit"; int year = 1;rate = Double.parsedouble (B2.gettext ()); n = integer.parseint (B3.gettext ()) ; if (B1.gettext () Equals ("")) {if (B4.gettext (). Equals ("")) {Joptionpane.showmessagedialog (null, "Enter the principal or expected value");} Else{amount = Double.parsedouble (B4.gettext ());p rincipal=0;while (year <= n) {principal = amount/(1 + rate* year); yea R = year + 1;} output= "Principal" +currencyformatter.format (Principal) + "\ n"; text.settext (output);}}  else {principal = Double.parsedouble (B1.gettext ());//String converted to numeric if (B4.gettext (). Equals ("")) {while (year <= N) {amount = Principal * (1 + rate* year), Output + = string.valueof (year) + "\t\t\t" + currencyformatter.format (amount) + "\ n"; year = Year + 1;} Text.settext (output);} Else{joptionpane.showmessagedialog (NULL, "the principal and expected value are entered in one can");}}} public static void Main (string[] args) {int Windowswidth=500;int Windowsheight=400;fuli frame = new Fuli (); frame.setvisib Le (True); Frame.setsize (Windowswidth, windowsheight); frame.setresizable (false); int width = Toolkit.Getdefaulttoolkit (). Getscreensize (). Width;int height = Toolkit.getdefaulttoolkit (). Getscreensize (). Height;        Frame.setlocation ((width-windowswidth)/2, (Height-windowsheight)/2); Window Center}}

interface and running results

0311 the simple interest and expectation of software engineering compound interest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.